delay, /* Current retry delay */
prev_delay; /* Next retry delay */
const char *uri; /* Printer URI */
- char resource[1024]; /* Resource path */
+ char resource[1024]; /* URI resource path */
int version; /* IPP version */
ipp_status_t status; /* Status of request */
_cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
DEBUG_printf(("cupsCopyDestInfo(http=%p, dest=%p(%s))", (void *)http, (void *)dest, dest ? dest->name : ""));
+ /*
+ * Range check input...
+ */
+
+ if (!dest)
+ return (NULL);
+
/*
* Get the default connection as needed...
*/
DEBUG_puts("1cupsCopyDestInfo: Default server connection.");
http = _cupsConnect();
dflags = CUPS_DEST_FLAGS_NONE;
+
+ if (!http)
+ return (NULL);
}
#ifdef AF_LOCAL
else if (httpAddrFamily(http->hostaddr) == AF_LOCAL)
dflags = CUPS_DEST_FLAGS_NONE;
}
#endif /* AF_LOCAL */
- else if ((strcmp(http->hostname, cg->server) && cg->server[0] != '/') || cg->ipp_port != httpAddrPort(http->hostaddr))
- {
- DEBUG_printf(("1cupsCopyDestInfo: Connection to device (%s).", http->hostname));
- dflags = CUPS_DEST_FLAGS_DEVICE;
- }
else
{
- DEBUG_printf(("1cupsCopyDestInfo: Connection to server (%s).", http->hostname));
- dflags = CUPS_DEST_FLAGS_NONE;
- }
+ // Guess the destination flags based on the printer URI's host and port...
+ char scheme[32], /* URI scheme */
+ userpass[256], /* URI username:password */
+ host[256]; /* URI host */
+ int port; /* URI port */
- /*
- * Range check input...
- */
+ if ((uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options)) == NULL || httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme), userpass, sizeof(userpass), host, sizeof(host), &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
+ {
+ strlcpy(host, "localhost", sizeof(host));
+ port = cg->ipp_port;
+ }
- if (!http || !dest)
- return (NULL);
+ if (strcmp(http->hostname, host) || port != httpAddrPort(http->hostaddr))
+ {
+ DEBUG_printf(("1cupsCopyDestInfo: Connection to device (%s).", http->hostname));
+ dflags = CUPS_DEST_FLAGS_DEVICE;
+ }
+ else
+ {
+ DEBUG_printf(("1cupsCopyDestInfo: Connection to server (%s).", http->hostname));
+ dflags = CUPS_DEST_FLAGS_NONE;
+ }
+ }
/*
* Get the printer URI and resource path...