]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/util.c
Fix build errors on Fedora.
[thirdparty/cups.git] / cups / util.c
index c9826549c3373ae1da455dbd6633adc698d18747..110142b65deac660fa1c1015665adc6c0abf92b3 100644 (file)
@@ -1,54 +1,18 @@
 /*
- * "$Id: util.c 7850 2008-08-20 00:07:25Z mike $"
+ * "$Id$"
  *
- *   Printing utilities for CUPS.
+ * Printing utilities for CUPS.
  *
- *   Copyright 2007-2012 by Apple Inc.
- *   Copyright 1997-2006 by Easy Software Products.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   These coded instructions, statements, and computer programs are the
- *   property of Apple Inc. and are protected by Federal copyright
- *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- *   which should have been included with this file.  If this file is
- *   file is missing or damaged, see the license at "http://www.cups.org/".
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file.  If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
  *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   cupsCancelJob()        - Cancel a print job on the default server.
- *   cupsCancelJob2()       - Cancel or purge a print 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
- *                            server.
- *   cupsGetDefault()       - Get the default printer or class for the default
- *                            server.
- *   cupsGetDefault2()      - Get the default printer or class for the specified
- *                            server.
- *   cupsGetJobs()          - Get the jobs from the default server.
- *   cupsGetJobs2()         - Get the jobs from the specified server.
- *   cupsGetPPD()           - Get the PPD file for a printer on the default
- *                            server.
- *   cupsGetPPD2()          - Get the PPD file for a printer from the specified
- *                            server.
- *   cupsGetPPD3()          - Get the PPD file for a printer on the specified
- *                            server if it has changed.
- *   cupsGetPrinters()      - Get a list of printers from the default server.
- *   cupsGetServerPPD()     - Get an available PPD file from the server.
- *   cupsPrintFile()        - Print a file to a printer or class on the default
- *                            server.
- *   cupsPrintFile2()       - Print a file to a printer or class on the
- *                            specified server.
- *   cupsPrintFiles()       - Print one or more files to a printer or class on
- *                            the default server.
- *   cupsPrintFiles2()      - Print one or more files to a printer or class on
- *                            the specified server.
- *   cupsStartDocument()    - Add a document to a job created with
- *                            cupsCreateJob().
- *   cups_get_printer_uri() - Get the printer-uri-supported attribute for the
- *                            first printer in a class.
+ * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
@@ -90,7 +54,7 @@ cupsCancelJob(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 */
 {
   return (cupsCancelJob2(CUPS_HTTP_DEFAULT, name, job_id, 0)
-              < IPP_REDIRECTION_OTHER_SITE);
+              < IPP_STATUS_REDIRECTION_OTHER_SITE);
 }
 
 
@@ -125,7 +89,7 @@ cupsCancelJob2(http_t     *http,     /* I - Connection to server or @code CUPS_HTTP_
 
   if (job_id < -1 || (!name && job_id == 0))
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
     return (0);
   }
 
@@ -135,7 +99,7 @@ cupsCancelJob2(http_t     *http,     /* I - Connection to server or @code CUPS_HTTP_
 
   if (!http)
     if ((http = _cupsConnect()) == NULL)
-      return (IPP_SERVICE_UNAVAILABLE);
+      return (IPP_STATUS_ERROR_SERVICE_UNAVAILABLE);
 
  /*
   * Build an IPP_CANCEL_JOB or IPP_PURGE_JOBS request, which requires the following
@@ -148,7 +112,7 @@ cupsCancelJob2(http_t     *http,    /* I - Connection to server or @code CUPS_HTTP_
   *    [purge-job] or [purge-jobs]
   */
 
-  request = ippNewRequest(job_id < 0 ? IPP_PURGE_JOBS : IPP_CANCEL_JOB);
+  request = ippNewRequest(job_id < 0 ? IPP_OP_PURGE_JOBS : IPP_OP_CANCEL_JOB);
 
   if (name)
   {
@@ -223,7 +187,7 @@ cupsCreateJob(
 
   if (!name)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
     return (0);
   }
 
@@ -231,9 +195,9 @@ cupsCreateJob(
   * Build a Create-Job request...
   */
 
-  if ((request = ippNewRequest(IPP_CREATE_JOB)) == NULL)
+  if ((request = ippNewRequest(IPP_OP_CREATE_JOB)) == NULL)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, strerror(ENOMEM), 0);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOMEM), 0);
     return (0);
   }
 
@@ -248,6 +212,7 @@ cupsCreateJob(
   if (title)
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
                  title);
+  cupsEncodeOptions2(request, num_options, options, IPP_TAG_OPERATION);
   cupsEncodeOptions2(request, num_options, options, IPP_TAG_JOB);
   cupsEncodeOptions2(request, num_options, options, IPP_TAG_SUBSCRIPTION);
 
@@ -341,7 +306,7 @@ cupsGetClasses(char ***classes)             /* O - Classes */
 
   if (!classes)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
 
     return (0);
   }
@@ -360,7 +325,7 @@ cupsGetClasses(char ***classes)             /* O - Classes */
   *    requested-attributes
   */
 
-  request = ippNewRequest(CUPS_GET_CLASSES);
+  request = ippNewRequest(IPP_OP_CUPS_GET_CLASSES);
 
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
                "requested-attributes", NULL, "printer-name");
@@ -381,7 +346,7 @@ cupsGetClasses(char ***classes)             /* O - Classes */
         if (n == 0)
          temp = malloc(sizeof(char *));
        else
-         temp = realloc(*classes, sizeof(char *) * (n + 1));
+         temp = realloc(*classes, sizeof(char *) * (size_t)(n + 1));
 
        if (temp == NULL)
        {
@@ -479,7 +444,7 @@ cupsGetDefault2(http_t *http)               /* I - Connection to server or @code CUPS_HTTP_DE
   *    attributes-natural-language
   */
 
-  request = ippNewRequest(CUPS_GET_DEFAULT);
+  request = ippNewRequest(IPP_OP_CUPS_GET_DEFAULT);
 
  /*
   * Do the request and get back a response...
@@ -585,7 +550,7 @@ cupsGetJobs2(http_t     *http,              /* I - Connection to server or @code CUPS_HTTP_D
 
   if (!jobs)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
 
     return (-1);
   }
@@ -597,9 +562,11 @@ cupsGetJobs2(http_t     *http,             /* I - Connection to server or @code CUPS_HTTP_D
   if (name)
   {
     if (httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
-                         "localhost", 0, "/printers/%s", name) != HTTP_URI_OK)
+                         "localhost", 0, "/printers/%s",
+                         name) < HTTP_URI_STATUS_OK)
     {
-      _cupsSetError(IPP_INTERNAL_ERROR, _("Unable to create printer-uri"), 1);
+      _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
+                    _("Unable to create printer-uri"), 1);
 
       return (-1);
     }
@@ -624,7 +591,7 @@ cupsGetJobs2(http_t     *http,              /* I - Connection to server or @code CUPS_HTTP_D
   *    requested-attributes
   */
 
-  request = ippNewRequest(IPP_GET_JOBS);
+  request = ippNewRequest(IPP_OP_GET_JOBS);
 
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                "printer-uri", NULL, uri);
@@ -674,7 +641,7 @@ cupsGetJobs2(http_t     *http,              /* I - Connection to server or @code CUPS_HTTP_D
       id              = 0;
       size            = 0;
       priority        = 50;
-      state           = IPP_JOB_PENDING;
+      state           = IPP_JSTATE_PENDING;
       user            = "unknown";
       dest            = NULL;
       format          = "application/octet-stream";
@@ -745,7 +712,7 @@ cupsGetJobs2(http_t     *http,              /* I - Connection to server or @code CUPS_HTTP_D
       if (n == 0)
         temp = malloc(sizeof(cups_job_t));
       else
-       temp = realloc(*jobs, sizeof(cups_job_t) * (n + 1));
+       temp = realloc(*jobs, sizeof(cups_job_t) * (size_t)(n + 1));
 
       if (!temp)
       {
@@ -753,7 +720,7 @@ cupsGetJobs2(http_t     *http,              /* I - Connection to server or @code CUPS_HTTP_D
         * Ran out of memory!
         */
 
-        _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
+        _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0);
 
        cupsFreeJobs(n, *jobs);
        *jobs = NULL;
@@ -790,7 +757,7 @@ cupsGetJobs2(http_t     *http,              /* I - Connection to server or @code CUPS_HTTP_D
     ippDelete(response);
   }
 
-  if (n == 0 && cg->last_error >= IPP_BAD_REQUEST)
+  if (n == 0 && cg->last_error >= IPP_STATUS_ERROR_BAD_REQUEST)
     return (-1);
   else
     return (n);
@@ -822,7 +789,7 @@ cupsGetPPD(const char *name)                /* I - Destination name */
   cg->ppd_filename[0] = '\0';
 
   if (cupsGetPPD3(CUPS_HTTP_DEFAULT, name, &modtime, cg->ppd_filename,
-                  sizeof(cg->ppd_filename)) == HTTP_OK)
+                  sizeof(cg->ppd_filename)) == HTTP_STATUS_OK)
     return (cg->ppd_filename);
   else
     return (NULL);
@@ -853,7 +820,7 @@ cupsGetPPD2(http_t     *http,               /* I - Connection to server or @code CUPS_HTTP_DE
   cg->ppd_filename[0] = '\0';
 
   if (cupsGetPPD3(http, name, &modtime, cg->ppd_filename,
-                  sizeof(cg->ppd_filename)) == HTTP_OK)
+                  sizeof(cg->ppd_filename)) == HTTP_STATUS_OK)
     return (cg->ppd_filename);
   else
     return (NULL);
@@ -873,8 +840,8 @@ cupsGetPPD2(http_t     *http,               /* I - Connection to server or @code CUPS_HTTP_DE
  * file will be overwritten as needed.  The caller "owns" the file that is
  * created and must @code unlink@ the returned filename.
  *
- * 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
+ * On success, @code HTTP_STATUS_OK@ is returned for a new PPD file and
+ * @code HTTP_STATUS_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
@@ -914,20 +881,20 @@ cupsGetPPD3(http_t     *http,             /* I  - HTTP connection or @code CUPS_HTTP_DEFAUL
 
   if (!name)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, _("No printer name"), 1);
-    return (HTTP_NOT_ACCEPTABLE);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No printer name"), 1);
+    return (HTTP_STATUS_NOT_ACCEPTABLE);
   }
 
   if (!modtime)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, _("No modification time"), 1);
-    return (HTTP_NOT_ACCEPTABLE);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No modification time"), 1);
+    return (HTTP_STATUS_NOT_ACCEPTABLE);
   }
 
   if (!buffer || bufsize <= 1)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, _("Bad filename buffer"), 1);
-    return (HTTP_NOT_ACCEPTABLE);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad filename buffer"), 1);
+    return (HTTP_STATUS_NOT_ACCEPTABLE);
   }
 
 #ifndef WIN32
@@ -935,10 +902,16 @@ cupsGetPPD3(http_t     *http,             /* I  - HTTP connection or @code CUPS_HTTP_DEFAUL
   * See if the PPD file is available locally...
   */
 
-  if (!cg->servername[0])
-    cupsServer();
+  if (http)
+    httpGetHostname(http, hostname, sizeof(hostname));
+  else
+  {
+    strlcpy(hostname, cupsServer(), sizeof(hostname));
+    if (hostname[0] == '/')
+      strlcpy(hostname, "localhost", sizeof(hostname));
+  }
 
-  if (!_cups_strcasecmp(cg->servername, "localhost"))
+  if (!_cups_strcasecmp(hostname, "localhost"))
   {
     char       ppdname[1024];          /* PPD filename */
     struct stat        ppdinfo;                /* PPD file information */
@@ -958,9 +931,9 @@ cupsGetPPD3(http_t     *http,               /* I  - HTTP connection or @code CUPS_HTTP_DEFAUL
 
        if (symlink(ppdname, buffer) && errno != EEXIST)
         {
-          _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
+          _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0);
 
-         return (HTTP_SERVER_ERROR);
+         return (HTTP_STATUS_SERVER_ERROR);
        }
       }
       else
@@ -1018,18 +991,18 @@ cupsGetPPD3(http_t     *http,            /* I  - HTTP connection or @code CUPS_HTTP_DEFAUL
 
         if (tries >= 1000)
        {
-          _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
+          _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0);
 
-         return (HTTP_SERVER_ERROR);
+         return (HTTP_STATUS_SERVER_ERROR);
        }
       }
 
       if (*modtime >= ppdinfo.st_mtime)
-        return (HTTP_NOT_MODIFIED);
+        return (HTTP_STATUS_NOT_MODIFIED);
       else
       {
         *modtime = ppdinfo.st_mtime;
-       return (HTTP_OK);
+       return (HTTP_STATUS_OK);
       }
     }
   }
@@ -1041,11 +1014,11 @@ cupsGetPPD3(http_t     *http,           /* I  - HTTP connection or @code CUPS_HTTP_DEFAUL
 
   if (!http)
     if ((http = _cupsConnect()) == NULL)
-      return (HTTP_SERVICE_UNAVAILABLE);
+      return (HTTP_STATUS_SERVICE_UNAVAILABLE);
 
   if (!cups_get_printer_uri(http, name, hostname, sizeof(hostname), &port,
                             resource, sizeof(resource), 0))
-    return (HTTP_NOT_FOUND);
+    return (HTTP_STATUS_NOT_FOUND);
 
   DEBUG_printf(("2cupsGetPPD3: Printer hostname=\"%s\", port=%d", hostname,
                 port));
@@ -1066,7 +1039,7 @@ cupsGetPPD3(http_t     *http,             /* I  - HTTP connection or @code CUPS_HTTP_DEFAUL
   */
 
   httpGetHostname(http, http_hostname, sizeof(http_hostname));
-  http_port = _httpAddrPort(http->hostaddr);
+  http_port = httpAddrPort(http->hostaddr);
 
   DEBUG_printf(("2cupsGetPPD3: Connection hostname=\"%s\", port=%d",
                 http_hostname, http_port));
@@ -1077,12 +1050,12 @@ cupsGetPPD3(http_t     *http,           /* I  - HTTP connection or @code CUPS_HTTP_DEFAUL
 
   if (!_cups_strcasecmp(http_hostname, hostname) && port == http_port)
     http2 = http;
-  else if ((http2 = httpConnectEncrypt(hostname, port,
-                                       cupsEncryption())) == NULL)
+  else if ((http2 = httpConnect2(hostname, port, NULL, AF_UNSPEC,
+                                cupsEncryption(), 1, 30000, NULL)) == NULL)
   {
     DEBUG_puts("1cupsGetPPD3: Unable to connect to server");
 
-    return (HTTP_SERVICE_UNAVAILABLE);
+    return (HTTP_STATUS_SERVICE_UNAVAILABLE);
   }
 
  /*
@@ -1100,12 +1073,12 @@ cupsGetPPD3(http_t     *http,           /* I  - HTTP connection or @code CUPS_HTTP_DEFAUL
     * Can't open file; close the server connection and return NULL...
     */
 
-    _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0);
 
     if (http2 != http)
       httpClose(http2);
 
-    return (HTTP_SERVER_ERROR);
+    return (HTTP_STATUS_SERVER_ERROR);
   }
 
  /*
@@ -1126,14 +1099,14 @@ cupsGetPPD3(http_t     *http,           /* I  - HTTP connection or @code CUPS_HTTP_DEFAUL
   * See if we actually got the file or an error...
   */
 
-  if (status == HTTP_OK)
+  if (status == HTTP_STATUS_OK)
   {
     *modtime = httpGetDateTime(httpGetField(http2, HTTP_FIELD_DATE));
 
     if (tempfile[0])
       strlcpy(buffer, tempfile, bufsize);
   }
-  else if (status != HTTP_NOT_MODIFIED)
+  else if (status != HTTP_STATUS_NOT_MODIFIED)
   {
     _cupsSetHTTPError(status);
 
@@ -1183,7 +1156,7 @@ cupsGetPrinters(char ***printers) /* O - Printers */
 
   if (!printers)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
 
     return (0);
   }
@@ -1206,7 +1179,7 @@ cupsGetPrinters(char ***printers) /* O - Printers */
   *    requested-attributes
   */
 
-  request = ippNewRequest(CUPS_GET_PRINTERS);
+  request = ippNewRequest(IPP_OP_CUPS_GET_PRINTERS);
 
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
                "requested-attributes", NULL, "printer-name");
@@ -1233,7 +1206,7 @@ cupsGetPrinters(char ***printers) /* O - Printers */
         if (n == 0)
          temp = malloc(sizeof(char *));
        else
-         temp = realloc(*printers, sizeof(char *) * (n + 1));
+         temp = realloc(*printers, sizeof(char *) * (size_t)(n + 1));
 
        if (temp == NULL)
        {
@@ -1295,7 +1268,7 @@ cupsGetServerPPD(http_t     *http,        /* I - Connection to server or @code CUPS_HTT
 
   if (!name)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, _("No PPD name"), 1);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No PPD name"), 1);
 
     return (NULL);
   }
@@ -1314,7 +1287,7 @@ cupsGetServerPPD(http_t     *http,        /* I - Connection to server or @code CUPS_HTT
     * Can't open file; close the server connection and return NULL...
     */
 
-    _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0);
 
     return (NULL);
   }
@@ -1323,7 +1296,7 @@ cupsGetServerPPD(http_t     *http,        /* I - Connection to server or @code CUPS_HTT
   * Get the PPD file...
   */
 
-  request = ippNewRequest(CUPS_GET_PPD);
+  request = ippNewRequest(IPP_OP_CUPS_GET_PPD);
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "ppd-name", NULL,
                name);
 
@@ -1331,7 +1304,7 @@ cupsGetServerPPD(http_t     *http,        /* I - Connection to server or @code CUPS_HTT
 
   close(fd);
 
-  if (cupsLastError() != IPP_OK)
+  if (cupsLastError() != IPP_STATUS_OK)
   {
     unlink(cg->ppd_filename);
     return (NULL);
@@ -1453,7 +1426,7 @@ cupsPrintFiles2(
 
   if (!name || num_files < 1 || !files)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
 
     return (0);
   }
@@ -1492,20 +1465,20 @@ cupsPrintFiles2(
       * Unable to open print file, cancel the job and return...
       */
 
-      _cupsSetError(IPP_DOCUMENT_ACCESS_ERROR, NULL, 0);
+      _cupsSetError(IPP_STATUS_ERROR_DOCUMENT_ACCESS, NULL, 0);
       goto cancel_job;
     }
 
     status = cupsStartDocument(http, name, job_id, docname, format,
                               i == (num_files - 1));
 
-    while (status == HTTP_CONTINUE &&
+    while (status == HTTP_STATUS_CONTINUE &&
           (bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)
-      status = cupsWriteRequestData(http, buffer, bytes);
+      status = cupsWriteRequestData(http, buffer, (size_t)bytes);
 
     cupsFileClose(fp);
 
-    if (status != HTTP_CONTINUE || cupsFinishDocument(http, name) != IPP_OK)
+    if (status != HTTP_STATUS_CONTINUE || cupsFinishDocument(http, name) != IPP_STATUS_OK)
     {
      /*
       * Unable to queue, cancel the job and return...
@@ -1571,10 +1544,10 @@ cupsStartDocument(
   * Create a Send-Document request...
   */
 
-  if ((request = ippNewRequest(IPP_SEND_DOCUMENT)) == NULL)
+  if ((request = ippNewRequest(IPP_OP_SEND_DOCUMENT)) == NULL)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, strerror(ENOMEM), 0);
-    return (HTTP_ERROR);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOMEM), 0);
+    return (HTTP_STATUS_ERROR);
   }
 
   httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri), "ipp",
@@ -1592,7 +1565,7 @@ cupsStartDocument(
   if (format)
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE,
                  "document-format", NULL, format);
-  ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", last_document);
+  ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", (char)last_document);
 
  /*
   * Send and delete the request, then return the status...
@@ -1652,9 +1625,11 @@ cups_get_printer_uri(
   */
 
   if (httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
-                       "localhost", 0, "/printers/%s", name) != HTTP_URI_OK)
+                       "localhost", 0, "/printers/%s",
+                       name) < HTTP_URI_STATUS_OK)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, _("Unable to create printer-uri"), 1);
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to create printer-uri"),
+                  1);
 
     *host     = '\0';
     *resource = '\0';
@@ -1669,7 +1644,7 @@ cups_get_printer_uri(
   */
 
   httpGetHostname(http, http_hostname, sizeof(http_hostname));
-  http_port = _httpAddrPort(http->hostaddr);
+  http_port = httpAddrPort(http->hostaddr);
 
  /*
   * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the following
@@ -1681,7 +1656,7 @@ cups_get_printer_uri(
   *    requested-attributes
   */
 
-  request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+  request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
 
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
                NULL, uri);
@@ -1695,7 +1670,9 @@ cups_get_printer_uri(
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(http, request, "/")) != NULL)
+  snprintf(resource, (size_t)resourcesize, "/printers/%s", name);
+
+  if ((response = cupsDoRequest(http, request, resource)) != NULL)
   {
     const char *device_uri = NULL;     /* device-uri value */
 
@@ -1704,12 +1681,14 @@ cups_get_printer_uri(
       device_uri = attr->values[0].string.text;
 
     if (device_uri &&
-        ((strstr(device_uri, "._ipp.") != NULL ||
-          strstr(device_uri, "._ipps.") != NULL) &&
-         !strcmp(device_uri + strlen(device_uri) - 5, "/cups")))
+        (!strncmp(device_uri, "ipp://", 6) ||
+         !strncmp(device_uri, "ipps://", 7) ||
+         ((strstr(device_uri, "._ipp.") != NULL ||
+           strstr(device_uri, "._ipps.") != NULL) &&
+          !strcmp(device_uri + strlen(device_uri) - 5, "/cups"))))
     {
      /*
-      * Statically-configured Bonjour shared printer.
+      * Statically-configured shared printer.
       */
 
       httpSeparateURI(HTTP_URI_CODING_ALL,
@@ -1765,8 +1744,9 @@ cups_get_printer_uri(
 
            if (!_cups_strcasecmp(http_hostname, host) && *port == http_port)
              http2 = http;
-           else if ((http2 = httpConnectEncrypt(host, *port,
-                                                cupsEncryption())) == NULL)
+           else if ((http2 = httpConnect2(host, *port, NULL, AF_UNSPEC,
+                                          cupsEncryption(), 1, 30000,
+                                          NULL)) == NULL)
            {
              DEBUG_puts("8cups_get_printer_uri: Unable to connect to server");
 
@@ -1808,7 +1788,7 @@ cups_get_printer_uri(
 
       if (!strncmp(resource, "/classes/", 9))
       {
-        _cupsSetError(IPP_INTERNAL_ERROR,
+        _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                      _("No printer-uri found for class"), 1);
 
        *host     = '\0';
@@ -1823,8 +1803,8 @@ cups_get_printer_uri(
     ippDelete(response);
   }
 
-  if (cupsLastError() != IPP_NOT_FOUND)
-    _cupsSetError(IPP_INTERNAL_ERROR, _("No printer-uri found"), 1);
+  if (cupsLastError() != IPP_STATUS_ERROR_NOT_FOUND)
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No printer-uri found"), 1);
 
   *host     = '\0';
   *resource = '\0';
@@ -1834,5 +1814,5 @@ cups_get_printer_uri(
 
 
 /*
- * End of "$Id: util.c 7850 2008-08-20 00:07:25Z mike $".
+ * End of "$Id$".
  */