/*
- * "$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).
*
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 */
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);
}
* 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);
* 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)
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 */
strlcpy(hostbuf, cupsServer(), sizeof(hostbuf));
+ httpGetHostname(cg->http, http_hostname, sizeof(http_hostname));
+
if (hostname != NULL)
strlcpy(hostname, hostbuf, HTTP_MAX_URI);
else
if (cg->http != NULL)
{
- if (!strcasecmp(cg->http->hostname, hostname))
+ if (!strcasecmp(http_hostname, hostname))
return (printer);
httpClose(cg->http);
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",
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';
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);
* 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)
ippDelete(response);
}
+ _cupsSetError(IPP_INTERNAL_ERROR, "No printer-uri found!");
+
*host = '\0';
*resource = '\0';
/*
- * 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 $".
*/