]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/util.c
Remove svn:keywords since they cause svn_load_dirs.pl to complain about every file.
[thirdparty/cups.git] / cups / util.c
index 25565073798a00ec17241d4c00ddf312bead2839..42aa4622db6c14ce2cb31d8cb22ef1e262ad8029 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: util.c 5138 2006-02-21 10:49:06Z mike $"
+ * "$Id: util.c 181 2006-06-22 20:01:18Z jlovell $"
  *
  *   Printing utilities for the Common UNIX Printing System (CUPS).
  *
@@ -800,6 +800,8 @@ cupsGetPPD2(http_t     *http,               /* I - HTTP connection */
             const char *name)          /* I - Printer name */
 {
   int          http_port;              /* Port number */
+  char         http_hostname[HTTP_MAX_HOST];
+                                       /* Hostname associated with connection */
   http_t       *http2;                 /* Alternate HTTP connection */
   int          fd;                     /* PPD file */
   char         localhost[HTTP_MAX_URI],/* Local hostname */
@@ -819,7 +821,10 @@ cupsGetPPD2(http_t     *http,              /* I - HTTP connection */
 
   if (!http || !name)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, NULL);
+    if (!http)
+      _cupsSetError(IPP_INTERNAL_ERROR, "No HTTP connection!");
+    else
+      _cupsSetError(IPP_INTERNAL_ERROR, "No printer name!");
 
     return (NULL);
   }
@@ -836,15 +841,17 @@ cupsGetPPD2(http_t     *http,             /* I - HTTP connection */
   * Remap local hostname to localhost...
   */
 
-  httpGetHostname(localhost, sizeof(localhost));
+  httpGetHostname(NULL, localhost, sizeof(localhost));
 
   if (!strcasecmp(localhost, hostname))
     strcpy(hostname, "localhost");
 
  /*
-  * Get the port number we are connected to...
+  * 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);
@@ -859,7 +866,7 @@ cupsGetPPD2(http_t     *http,               /* I - HTTP connection */
   * Reconnect to the correct server as needed...
   */
 
-  if (!strcasecmp(http->hostname, hostname) && port == http_port)
+  if (!strcasecmp(http_hostname, hostname) && port == http_port)
     http2 = http;
   else if ((http2 = httpConnectEncrypt(hostname, port,
                                        cupsEncryption())) == NULL)
@@ -1391,7 +1398,8 @@ cups_connect(const char *name,            /* I - Destination (printer[@host]) */
             char       *printer,       /* O - Printer name [HTTP_MAX_URI] */
              char       *hostname)     /* O - Hostname [HTTP_MAX_URI] */
 {
-  char hostbuf[HTTP_MAX_URI];          /* Name of host */
+  char hostbuf[HTTP_MAX_URI],          /* Name of host */
+       http_hostname[HTTP_MAX_HOST];   /* Hostname associated with connection */
   _cups_globals_t  *cg = _cupsGlobals();/* Pointer to library globals */
 
 
@@ -1412,6 +1420,8 @@ cups_connect(const char *name,            /* I - Destination (printer[@host]) */
 
   strlcpy(hostbuf, cupsServer(), sizeof(hostbuf));
 
+  httpGetHostname(cg->http, http_hostname, sizeof(http_hostname));
+
   if (hostname != NULL)
     strlcpy(hostname, hostbuf, HTTP_MAX_URI);
   else
@@ -1424,7 +1434,7 @@ cups_connect(const char *name,            /* I - Destination (printer[@host]) */
 
   if (cg->http != NULL)
   {
-    if (!strcasecmp(cg->http->hostname, hostname))
+    if (!strcasecmp(http_hostname, hostname))
       return (printer);
 
     httpClose(cg->http);
@@ -1470,7 +1480,9 @@ cups_get_printer_uri(
   char         uri[HTTP_MAX_URI],      /* printer-uri attribute */
                scheme[HTTP_MAX_URI],   /* Scheme name */
                username[HTTP_MAX_URI], /* Username:password */
-               classname[255];         /* Temporary class name */
+               classname[255],         /* Temporary class name */
+               http_hostname[HTTP_MAX_HOST];
+                                       /* Hostname associated with connection */
   static const char * const requested_attrs[] =
                {                       /* Requested attributes */
                  "printer-uri-supported",
@@ -1491,7 +1503,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, NULL);
+    _cupsSetError(IPP_INTERNAL_ERROR, "Unable to create printer-uri!");
 
     *host     = '\0';
     *resource = '\0';
@@ -1502,9 +1514,11 @@ cups_get_printer_uri(
   DEBUG_printf(("cups_get_printer_uri: printer-uri=\"%s\"\n", uri));
 
  /*
-  * Get the port number we are connected to...
+  * 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);
@@ -1582,7 +1596,7 @@ cups_get_printer_uri(
            * Found a class!  Connect to the right server...
            */
 
-           if (!strcasecmp(http->hostname, host) && *port == http_port)
+           if (!strcasecmp(http_hostname, host) && *port == http_port)
              http2 = http;
            else if ((http2 = httpConnectEncrypt(host, *port,
                                                 cupsEncryption())) == NULL)
@@ -1628,6 +1642,8 @@ cups_get_printer_uri(
     ippDelete(response);
   }
 
+  _cupsSetError(IPP_INTERNAL_ERROR, "No printer-uri found!");
+
   *host     = '\0';
   *resource = '\0';
 
@@ -1636,5 +1652,5 @@ cups_get_printer_uri(
 
 
 /*
- * End of "$Id: util.c 5138 2006-02-21 10:49:06Z mike $".
+ * End of "$Id: util.c 181 2006-06-22 20:01:18Z jlovell $".
  */