/*
- * "$Id: http-support.c 7952 2008-09-17 00:56:20Z mike $"
+ * "$Id$"
*
- * HTTP support routines for CUPS.
+ * HTTP support routines for CUPS.
*
- * Copyright 2007-2013 by Apple Inc.
- * Copyright 1997-2007 by Easy Software Products, all rights reserved.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
- * 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:
- *
- * httpAssembleURI() - Assemble a uniform resource identifier from its
- * components.
- * httpAssembleURIf() - Assemble a uniform resource identifier from its
- * components with a formatted resource.
- * httpAssembleUUID() - Assemble a name-based UUID URN conforming to RFC
- * 4122.
- * httpDecode64() - Base64-decode a string.
- * httpDecode64_2() - Base64-decode a string.
- * httpEncode64() - Base64-encode a string.
- * httpEncode64_2() - Base64-encode a string.
- * httpGetDateString() - Get a formatted date/time string from a time value.
- * httpGetDateString2() - Get a formatted date/time string from a time value.
- * httpGetDateTime() - Get a time value from a formatted date/time string.
- * httpSeparate() - Separate a Universal Resource Identifier into its
- * components.
- * httpSeparate2() - Separate a Universal Resource Identifier into its
- * components.
- * httpSeparateURI() - Separate a Universal Resource Identifier into its
- * components.
- * httpStatus() - Return a short string describing a HTTP status
- * code.
- * _cups_hstrerror() - hstrerror() emulation function for Solaris and
- * others.
- * _httpDecodeURI() - Percent-decode a HTTP request URI.
- * _httpEncodeURI() - Percent-encode a HTTP request URI.
- * _httpResolveURI() - Resolve a DNS-SD URI.
- * http_client_cb() - Client callback for resolving URI.
- * http_copy_decode() - Copy and decode a URI.
- * http_copy_encode() - Copy and encode a URI.
- * http_poll_cb() - Wait for input on the specified file descriptors.
- * http_resolve_cb() - Build a device URI for the given service name.
- * http_resolve_cb() - Build a device URI for the given service name.
+ * This file is subject to the Apple OS-Developed Software exception.
*/
/*
size_t bufsize; /* Size of buffer */
int options; /* Options passed to _httpResolveURI */
const char *resource; /* Resource from URI */
+ const char *uuid; /* UUID from URI */
} _http_uribuf_t;
* Local globals...
*/
-static const char * const http_days[7] =
+static const char * const http_days[7] =/* Days of the week */
{
"Sun",
"Mon",
"Sat"
};
static const char * const http_months[12] =
- {
+ { /* Months of the year */
"Jan",
"Feb",
"Mar",
"Nov",
"Dec"
};
+static const char * const http_states[] =
+ { /* HTTP state strings */
+ "HTTP_STATE_ERROR",
+ "HTTP_STATE_WAITING",
+ "HTTP_STATE_OPTIONS",
+ "HTTP_STATE_GET",
+ "HTTP_STATE_GET_SEND",
+ "HTTP_STATE_HEAD",
+ "HTTP_STATE_POST",
+ "HTTP_STATE_POST_RECV",
+ "HTTP_STATE_POST_SEND",
+ "HTTP_STATE_PUT",
+ "HTTP_STATE_PUT_RECV",
+ "HTTP_STATE_DELETE",
+ "HTTP_STATE_TRACE",
+ "HTTP_STATE_CONNECT",
+ "HTTP_STATE_STATUS",
+ "HTTP_STATE_UNKNOWN_METHOD",
+ "HTTP_STATE_UNKNOWN_VERSION"
+ };
/*
if (uri)
*uri = '\0';
- return (HTTP_URI_BAD_ARGUMENTS);
+ return (HTTP_URI_STATUS_BAD_ARGUMENTS);
}
/*
if (!ptr)
goto assemble_overflow;
- if (!strcmp(scheme, "mailto"))
+ if (!strcmp(scheme, "mailto") || !strcmp(scheme, "tel"))
{
/*
- * mailto: only has :, no //...
+ * mailto: and tel: only have :, no //...
*/
if (ptr < end)
else
{
/*
- * Schemes other than mailto: all have //...
+ * Schemes other than mailto: and tel: all have //...
*/
if ((ptr + 2) < end)
if (host)
{
+ const char *hostptr; /* Pointer into hostname */
+ int have_ipv6; /* Do we have an IPv6 address? */
+
if (username && *username)
{
/*
* too...
*/
- if (host[0] != '[' && strchr(host, ':') && !strstr(host, "._tcp"))
+ for (hostptr = host,
+ have_ipv6 = strchr(host, ':') && !strstr(host, "._tcp");
+ *hostptr && have_ipv6;
+ hostptr ++)
+ if (*hostptr != ':' && !isxdigit(*hostptr & 255))
+ {
+ have_ipv6 = *hostptr == '%';
+ break;
+ }
+
+ if (have_ipv6)
{
/*
* We have a raw IPv6 address...
*/
- if (strchr(host, '%'))
+ if (strchr(host, '%') && !(encoding & HTTP_URI_CODING_RFC6874))
{
/*
* We have a link-local address, add "[v1." prefix...
else
{
/*
- * We have a normal address, add "[" prefix...
+ * We have a normal (or RFC 6874 link-local) address, add "[" prefix...
*/
if (ptr < end)
while (ptr < end && *host)
{
if (*host == '%')
- {
- *ptr++ = '+'; /* Convert zone separator */
+ {
+ /*
+ * Convert/encode zone separator
+ */
+
+ if (encoding & HTTP_URI_CODING_RFC6874)
+ {
+ if (ptr >= (end - 2))
+ goto assemble_overflow;
+
+ *ptr++ = '%';
+ *ptr++ = '2';
+ *ptr++ = '5';
+ }
+ else
+ *ptr++ = '+';
+
host ++;
}
else
else
{
/*
- * Otherwise, just copy the host string...
+ * Otherwise, just copy the host string (the extra chars are not in the
+ * "reg-name" ABNF rule; anything <= SP or >= DEL plus % gets automatically
+ * percent-encoded.
*/
- ptr = http_copy_encode(ptr, host, end, "<>{}|^:/?#[]@\\\"", NULL,
+
+ ptr = http_copy_encode(ptr, host, end, "\"#/:<>?@[\\]^`{|}", NULL,
encoding & HTTP_URI_CODING_HOSTNAME);
if (!ptr)
if (port > 0)
{
- snprintf(ptr, end - ptr + 1, ":%d", port);
+ snprintf(ptr, (size_t)(end - ptr + 1), ":%d", port);
ptr += strlen(ptr);
if (ptr >= end)
*ptr = '\0';
- return (HTTP_URI_OK);
+ return (HTTP_URI_STATUS_OK);
/*
* Clear the URI string and return an overflow error; I don't usually
assemble_overflow:
*uri = '\0';
- return (HTTP_URI_OVERFLOW);
+ return (HTTP_URI_STATUS_OVERFLOW);
}
if (uri)
*uri = '\0';
- return (HTTP_URI_BAD_ARGUMENTS);
+ return (HTTP_URI_STATUS_BAD_ARGUMENTS);
}
/*
bytes = vsnprintf(resource, sizeof(resource), resourcef, ap);
va_end(ap);
- if (bytes >= sizeof(resource))
+ if ((size_t)bytes >= sizeof(resource))
{
*uri = '\0';
- return (HTTP_URI_OVERFLOW);
+ return (HTTP_URI_STATUS_OVERFLOW);
}
else
return (httpAssembleURI(encoding, uri, urilen, scheme, username, host,
* number. The result is formatted as a UUID URN as defined in RFC 4122.
*
* The buffer needs to be at least 46 bytes in size.
+ *
+ * @since CUPS 1.7/OS X 10.9@
*/
char * /* I - UUID string */
(unsigned)CUPS_RAND() & 0xffff, (unsigned)CUPS_RAND() & 0xffff);
_cupsMD5Init(&md5state);
- _cupsMD5Append(&md5state, (unsigned char *)data, strlen(data));
+ _cupsMD5Append(&md5state, (unsigned char *)data, (int)strlen(data));
_cupsMD5Finish(&md5state, md5sum);
/*
return (buffer);
}
-/* For OS X 10.8 and earlier */
-char *_httpAssembleUUID(const char *server, int port, const char *name,
- int number, char *buffer, size_t bufsize)
-{
- return (httpAssembleUUID(server, port, name, number, buffer, bufsize));
-}
-
/*
* 'httpDecode64()' - Base64-decode a string.
int *outlen, /* IO - Size of output string */
const char *in) /* I - String to read from */
{
- int pos, /* Bit position */
- base64; /* Value of this character */
- char *outptr, /* Output pointer */
- *outend; /* End of output buffer */
+ int pos; /* Bit position */
+ unsigned base64; /* Value of this character */
+ char *outptr, /* Output pointer */
+ *outend; /* End of output buffer */
/*
*/
if (*in >= 'A' && *in <= 'Z')
- base64 = *in - 'A';
+ base64 = (unsigned)(*in - 'A');
else if (*in >= 'a' && *in <= 'z')
- base64 = *in - 'a' + 26;
+ base64 = (unsigned)(*in - 'a' + 26);
else if (*in >= '0' && *in <= '9')
- base64 = *in - '0' + 52;
+ base64 = (unsigned)(*in - '0' + 52);
else if (*in == '+')
base64 = 62;
else if (*in == '/')
{
case 0 :
if (outptr < outend)
- *outptr = base64 << 2;
+ *outptr = (char)(base64 << 2);
pos ++;
break;
case 1 :
if (outptr < outend)
- *outptr++ |= (base64 >> 4) & 3;
+ *outptr++ |= (char)((base64 >> 4) & 3);
if (outptr < outend)
- *outptr = (base64 << 4) & 255;
+ *outptr = (char)((base64 << 4) & 255);
pos ++;
break;
case 2 :
if (outptr < outend)
- *outptr++ |= (base64 >> 2) & 15;
+ *outptr++ |= (char)((base64 >> 2) & 15);
if (outptr < outend)
- *outptr = (base64 << 6) & 255;
+ *outptr = (char)((base64 << 6) & 255);
pos ++;
break;
case 3 :
tdate = gmtime(&t);
if (tdate)
- snprintf(s, slen, "%s, %02d %s %d %02d:%02d:%02d GMT",
- http_days[tdate->tm_wday], tdate->tm_mday,
- http_months[tdate->tm_mon], tdate->tm_year + 1900,
- tdate->tm_hour, tdate->tm_min, tdate->tm_sec);
+ snprintf(s, (size_t)slen, "%s, %02d %s %d %02d:%02d:%02d GMT", http_days[tdate->tm_wday], tdate->tm_mday, http_months[tdate->tm_mon], tdate->tm_year + 1900, tdate->tm_hour, tdate->tm_min, tdate->tm_sec);
else
s[0] = '\0';
if (!uri || !port || !scheme || schemelen <= 0 || !username ||
usernamelen <= 0 || !host || hostlen <= 0 || !resource ||
resourcelen <= 0)
- return (HTTP_URI_BAD_ARGUMENTS);
+ return (HTTP_URI_STATUS_BAD_ARGUMENTS);
if (!*uri)
- return (HTTP_URI_BAD_URI);
+ return (HTTP_URI_STATUS_BAD_URI);
/*
* Grab the scheme portion of the URI...
*/
- status = HTTP_URI_OK;
+ status = HTTP_URI_STATUS_OK;
if (!strncmp(uri, "//", 2))
{
* Workaround for HP IPP client bug...
*/
- strlcpy(scheme, "ipp", schemelen);
- status = HTTP_URI_MISSING_SCHEME;
+ strlcpy(scheme, "ipp", (size_t)schemelen);
+ status = HTTP_URI_STATUS_MISSING_SCHEME;
}
else if (*uri == '/')
{
* Filename...
*/
- strlcpy(scheme, "file", schemelen);
- status = HTTP_URI_MISSING_SCHEME;
+ strlcpy(scheme, "file", (size_t)schemelen);
+ status = HTTP_URI_STATUS_MISSING_SCHEME;
}
else
{
if (*uri != ':')
{
*scheme = '\0';
- return (HTTP_URI_BAD_SCHEME);
+ return (HTTP_URI_STATUS_BAD_SCHEME);
}
uri ++;
*port = 515;
else if (!strcmp(scheme, "socket")) /* Not yet registered with IANA... */
*port = 9100;
- else if (strcmp(scheme, "file") && strcmp(scheme, "mailto"))
- status = HTTP_URI_UNKNOWN_SCHEME;
+ else if (strcmp(scheme, "file") && strcmp(scheme, "mailto") && strcmp(scheme, "tel"))
+ status = HTTP_URI_STATUS_UNKNOWN_SCHEME;
/*
* Now see if we have a hostname...
if (!uri)
{
*username = '\0';
- return (HTTP_URI_BAD_USERNAME);
+ return (HTTP_URI_STATUS_BAD_USERNAME);
}
uri ++;
*/
uri ++;
- if (!strncmp(uri, "v1.", 3))
- uri += 3; /* Skip IPvN leader... */
+ if (*uri == 'v')
+ {
+ /*
+ * Skip IPvFuture ("vXXXX.") prefix...
+ */
+
+ uri ++;
+
+ while (isxdigit(*uri & 255))
+ uri ++;
+
+ if (*uri != '.')
+ {
+ *host = '\0';
+ return (HTTP_URI_STATUS_BAD_HOSTNAME);
+ }
+
+ uri ++;
+ }
uri = http_copy_decode(host, uri, hostlen, "]",
decoding & HTTP_URI_CODING_HOSTNAME);
if (!uri)
{
*host = '\0';
- return (HTTP_URI_BAD_HOSTNAME);
+ return (HTTP_URI_STATUS_BAD_HOSTNAME);
}
/*
if (*uri != ']')
{
*host = '\0';
- return (HTTP_URI_BAD_HOSTNAME);
+ return (HTTP_URI_STATUS_BAD_HOSTNAME);
}
uri ++;
*ptr = '%';
break;
}
+ else if (*ptr == '%')
+ {
+ /*
+ * Stop at zone separator (RFC 6874)
+ */
+
+ break;
+ }
else if (*ptr != ':' && *ptr != '.' && !isxdigit(*ptr & 255))
{
*host = '\0';
- return (HTTP_URI_BAD_HOSTNAME);
+ return (HTTP_URI_STATUS_BAD_HOSTNAME);
}
}
else
for (ptr = (char *)uri; *ptr; ptr ++)
if (strchr(":?/", *ptr))
break;
- else if (!strchr("abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "0123456789"
- "-._~"
- "%"
- "!$&'()*+,;=\\", *ptr))
+ else if (!strchr("abcdefghijklmnopqrstuvwxyz" /* unreserved */
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" /* unreserved */
+ "0123456789" /* unreserved */
+ "-._~" /* unreserved */
+ "%" /* pct-encoded */
+ "!$&'()*+,;=" /* sub-delims */
+ "\\", *ptr)) /* SMB domain */
{
*host = '\0';
- return (HTTP_URI_BAD_HOSTNAME);
+ return (HTTP_URI_STATUS_BAD_HOSTNAME);
}
/*
if (!uri)
{
*host = '\0';
- return (HTTP_URI_BAD_HOSTNAME);
+ return (HTTP_URI_STATUS_BAD_HOSTNAME);
}
}
if (!strcmp(scheme, "file") && strcmp(host, "localhost") && host[0])
{
*host = '\0';
- return (HTTP_URI_BAD_HOSTNAME);
+ return (HTTP_URI_STATUS_BAD_HOSTNAME);
}
/*
if (!isdigit(uri[1] & 255))
{
*port = 0;
- return (HTTP_URI_BAD_PORT);
+ return (HTTP_URI_STATUS_BAD_PORT);
}
- *port = strtol(uri + 1, (char **)&uri, 10);
+ *port = (int)strtol(uri + 1, (char **)&uri, 10);
if (*uri != '/' && *uri)
{
*port = 0;
- return (HTTP_URI_BAD_PORT);
+ return (HTTP_URI_STATUS_BAD_PORT);
}
}
}
* Hostname but no path...
*/
- status = HTTP_URI_MISSING_RESOURCE;
+ status = HTTP_URI_STATUS_MISSING_RESOURCE;
*resource = '/';
/*
char *resptr = resource + strlen(resource);
- uri = http_copy_decode(resptr, uri, resourcelen - (int)(resptr - resource),
- NULL, decoding & HTTP_URI_CODING_QUERY);
+ uri = http_copy_decode(resptr, uri,
+ resourcelen - (int)(resptr - resource), NULL,
+ decoding & HTTP_URI_CODING_QUERY);
}
}
if (!uri)
{
*resource = '\0';
- return (HTTP_URI_BAD_RESOURCE);
+ return (HTTP_URI_STATUS_BAD_RESOURCE);
}
/*
/*
- * 'httpStatus()' - Return a short string describing a HTTP status code.
+ * 'httpStateString()' - Return the string describing a HTTP state value.
*
- * The returned string is localized to the current POSIX locale and is based
- * on the status strings defined in RFC 2616.
+ * @since CUPS 2.0@
+ */
+
+const char * /* O - State string */
+httpStateString(http_state_t state) /* I - HTTP state value */
+{
+ if (state < HTTP_STATE_ERROR || state > HTTP_STATE_UNKNOWN_VERSION)
+ return ("HTTP_STATE_???");
+ else
+ return (http_states[state - HTTP_STATE_ERROR]);
+}
+
+
+/*
+ * '_httpStatus()' - Return the localized string describing a HTTP status code.
+ *
+ * The returned string is localized using the passed message catalog.
*/
const char * /* O - Localized status string */
-httpStatus(http_status_t status) /* I - HTTP status code */
+_httpStatus(cups_lang_t *lang, /* I - Language */
+ http_status_t status) /* I - HTTP status code */
{
const char *s; /* Status string */
- _cups_globals_t *cg = _cupsGlobals(); /* Global data */
-
- if (!cg->lang_default)
- cg->lang_default = cupsLangDefault();
switch (status)
{
- case HTTP_CONTINUE :
+ case HTTP_STATUS_ERROR :
+ s = strerror(errno);
+ break;
+ case HTTP_STATUS_CONTINUE :
s = _("Continue");
break;
- case HTTP_SWITCHING_PROTOCOLS :
+ case HTTP_STATUS_SWITCHING_PROTOCOLS :
s = _("Switching Protocols");
break;
- case HTTP_OK :
+ case HTTP_STATUS_OK :
s = _("OK");
break;
- case HTTP_CREATED :
+ case HTTP_STATUS_CREATED :
s = _("Created");
break;
- case HTTP_ACCEPTED :
+ case HTTP_STATUS_ACCEPTED :
s = _("Accepted");
break;
- case HTTP_NO_CONTENT :
+ case HTTP_STATUS_NO_CONTENT :
s = _("No Content");
break;
- case HTTP_MOVED_PERMANENTLY :
+ case HTTP_STATUS_MOVED_PERMANENTLY :
s = _("Moved Permanently");
break;
- case HTTP_SEE_OTHER :
+ case HTTP_STATUS_SEE_OTHER :
s = _("See Other");
break;
- case HTTP_NOT_MODIFIED :
+ case HTTP_STATUS_NOT_MODIFIED :
s = _("Not Modified");
break;
- case HTTP_BAD_REQUEST :
+ case HTTP_STATUS_BAD_REQUEST :
s = _("Bad Request");
break;
- case HTTP_UNAUTHORIZED :
- case HTTP_AUTHORIZATION_CANCELED :
+ case HTTP_STATUS_UNAUTHORIZED :
+ case HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED :
s = _("Unauthorized");
break;
- case HTTP_FORBIDDEN :
+ case HTTP_STATUS_FORBIDDEN :
s = _("Forbidden");
break;
- case HTTP_NOT_FOUND :
+ case HTTP_STATUS_NOT_FOUND :
s = _("Not Found");
break;
- case HTTP_REQUEST_TOO_LARGE :
+ case HTTP_STATUS_REQUEST_TOO_LARGE :
s = _("Request Entity Too Large");
break;
- case HTTP_URI_TOO_LONG :
+ case HTTP_STATUS_URI_TOO_LONG :
s = _("URI Too Long");
break;
- case HTTP_UPGRADE_REQUIRED :
+ case HTTP_STATUS_UPGRADE_REQUIRED :
s = _("Upgrade Required");
break;
- case HTTP_NOT_IMPLEMENTED :
+ case HTTP_STATUS_NOT_IMPLEMENTED :
s = _("Not Implemented");
break;
- case HTTP_NOT_SUPPORTED :
+ case HTTP_STATUS_NOT_SUPPORTED :
s = _("Not Supported");
break;
- case HTTP_EXPECTATION_FAILED :
+ case HTTP_STATUS_EXPECTATION_FAILED :
s = _("Expectation Failed");
break;
- case HTTP_SERVICE_UNAVAILABLE :
+ case HTTP_STATUS_SERVICE_UNAVAILABLE :
s = _("Service Unavailable");
break;
- case HTTP_SERVER_ERROR :
+ case HTTP_STATUS_SERVER_ERROR :
s = _("Internal Server Error");
break;
- case HTTP_PKI_ERROR :
+ case HTTP_STATUS_CUPS_PKI_ERROR :
s = _("SSL/TLS Negotiation Error");
break;
- case HTTP_WEBIF_DISABLED :
+ case HTTP_STATUS_CUPS_WEBIF_DISABLED :
s = _("Web Interface is Disabled");
break;
break;
}
+ return (_cupsLangString(lang, s));
+}
+
+
+/*
+ * 'httpStatus()' - Return a short string describing a HTTP status code.
+ *
+ * The returned string is localized to the current POSIX locale and is based
+ * on the status strings defined in RFC 2616.
+ */
+
+const char * /* O - Localized status string */
+httpStatus(http_status_t status) /* I - HTTP status code */
+{
+ _cups_globals_t *cg = _cupsGlobals(); /* Global data */
+
+
+ if (!cg->lang_default)
+ cg->lang_default = cupsLangDefault();
+
+ return (_httpStatus(cg->lang_default, status));
+}
+
+/*
+ * 'httpURIStatusString()' - Return a string describing a URI status code.
+ *
+ * @since CUPS 2.0@
+ */
+
+const char * /* O - Localized status string */
+httpURIStatusString(
+ http_uri_status_t status) /* I - URI status code */
+{
+ const char *s; /* Status string */
+ _cups_globals_t *cg = _cupsGlobals(); /* Global data */
+
+
+ if (!cg->lang_default)
+ cg->lang_default = cupsLangDefault();
+
+ switch (status)
+ {
+ case HTTP_URI_STATUS_OVERFLOW :
+ s = _("URI too large");
+ break;
+ case HTTP_URI_STATUS_BAD_ARGUMENTS :
+ s = _("Bad arguments to function");
+ break;
+ case HTTP_URI_STATUS_BAD_RESOURCE :
+ s = _("Bad resource in URI");
+ break;
+ case HTTP_URI_STATUS_BAD_PORT :
+ s = _("Bad port number in URI");
+ break;
+ case HTTP_URI_STATUS_BAD_HOSTNAME :
+ s = _("Bad hostname/address in URI");
+ break;
+ case HTTP_URI_STATUS_BAD_USERNAME :
+ s = _("Bad username in URI");
+ break;
+ case HTTP_URI_STATUS_BAD_SCHEME :
+ s = _("Bad scheme in URI");
+ break;
+ case HTTP_URI_STATUS_BAD_URI :
+ s = _("Bad/empty URI");
+ break;
+ case HTTP_URI_STATUS_OK :
+ s = _("OK");
+ break;
+ case HTTP_URI_STATUS_MISSING_SCHEME :
+ s = _("Missing scheme in URI");
+ break;
+ case HTTP_URI_STATUS_UNKNOWN_SCHEME :
+ s = _("Unknown scheme in URI");
+ break;
+ case HTTP_URI_STATUS_MISSING_RESOURCE :
+ s = _("Missing resource in URI");
+ break;
+
+ default:
+ s = _("Unknown");
+ break;
+ }
+
return (_cupsLangString(cg->lang_default, s));
}
if ((status = httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme,
sizeof(scheme), userpass, sizeof(userpass),
hostname, sizeof(hostname), &port, resource,
- sizeof(resource))) < HTTP_URI_OK)
+ sizeof(resource))) < HTTP_URI_STATUS_OK)
#else
if (httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme,
sizeof(scheme), userpass, sizeof(userpass),
hostname, sizeof(hostname), &port, resource,
- sizeof(resource)) < HTTP_URI_OK)
+ sizeof(resource)) < HTTP_URI_STATUS_OK)
#endif /* DEBUG */
{
if (options & _HTTP_RESOLVE_STDERR)
{
#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
char *regtype, /* Pointer to type in hostname */
- *domain; /* Pointer to domain in hostname */
+ *domain, /* Pointer to domain in hostname */
+ *uuid, /* Pointer to UUID in URI */
+ *uuidend; /* Pointer to end of UUID in URI */
_http_uribuf_t uribuf; /* URI buffer */
int offline = 0; /* offline-report state set? */
# ifdef HAVE_DNSSD
# pragma comment(lib, "dnssd.lib")
# endif /* WIN32 */
DNSServiceRef ref, /* DNS-SD master service reference */
- domainref, /* DNS-SD service reference for domain */
+ domainref = NULL,/* DNS-SD service reference for domain */
localref; /* DNS-SD service reference for .local */
int domainsent = 0; /* Send the domain resolve? */
# ifdef HAVE_POLL
if (domain)
*domain++ = '\0';
+ if ((uuid = strstr(resource, "?uuid=")) != NULL)
+ {
+ *uuid = '\0';
+ uuid += 6;
+ if ((uuidend = strchr(uuid, '&')) != NULL)
+ *uuidend = '\0';
+ }
+
+ resolved_uri[0] = '\0';
+
uribuf.buffer = resolved_uri;
uribuf.bufsize = resolved_size;
uribuf.options = options;
uribuf.resource = resource;
-
- resolved_uri[0] = '\0';
+ uribuf.uuid = uuid;
DEBUG_printf(("6_httpResolveURI: Resolving hostname=\"%s\", regtype=\"%s\", "
"domain=\"%s\"\n", hostname, regtype, domain));
# ifdef HAVE_DNSSD
if (DNSServiceCreateConnection(&ref) == kDNSServiceErr_NoError)
{
- int myinterface = kDNSServiceInterfaceIndexAny;
+ uint32_t myinterface = kDNSServiceInterfaceIndexAny;
/* Lookup on any interface */
if (!strcmp(scheme, "ippusb"))
polldata.fd = DNSServiceRefSockFD(ref);
polldata.events = POLLIN;
- fds = poll(&polldata, 1, 1000 * timeout);
+ fds = poll(&polldata, 1, (int)(1000 * timeout));
# else /* select() */
FD_ZERO(&input_set);
}
else
{
- if (DNSServiceProcessResult(ref) == kDNSServiceErr_NoError)
+ if (DNSServiceProcessResult(ref) == kDNSServiceErr_NoError &&
+ resolved_uri[0])
{
uri = resolved_uri;
break;
else
quoted |= *src - '0';
- *ptr++ = quoted;
+ *ptr++ = (char)quoted;
}
else
{
return (NULL);
}
}
+ else if ((*src & 255) <= 0x20 || (*src & 255) >= 0x7f)
+ {
+ *ptr = '\0';
+ return (NULL);
+ }
else
*ptr++ = *src;
}
interfaceIndex, errorCode, fullName, hostTarget, port, txtLen,
txtRecord, context));
+ /*
+ * If we have a UUID, compare it...
+ */
+
+ if (uribuf->uuid &&
+ (value = TXTRecordGetValuePtr(txtLen, txtRecord, "UUID",
+ &valueLen)) != NULL)
+ {
+ char uuid[256]; /* UUID value */
+
+ memcpy(uuid, value, valueLen);
+ uuid[valueLen] = '\0';
+
+ if (_cups_strcasecmp(uuid, uribuf->uuid))
+ {
+ if (uribuf->options & _HTTP_RESOLVE_STDERR)
+ fprintf(stderr, "DEBUG: Found UUID %s, looking for %s.", uuid,
+ uribuf->uuid);
+
+ DEBUG_printf(("7http_resolve_cb: Found UUID %s, looking for %s.", uuid,
+ uribuf->uuid));
+ return;
+ }
+ }
+
/*
* Figure out the scheme from the full name...
*/
*/
if ((uribuf->options & _HTTP_RESOLVE_FAXOUT) &&
- (!strcmp(scheme, "ipp") || !strcmp(scheme, "ipps")))
+ (!strcmp(scheme, "ipp") || !strcmp(scheme, "ipps")) &&
+ !TXTRecordGetValuePtr(txtLen, txtRecord, "printer-type", &valueLen))
{
reskey = "rfo";
resdefault = "/ipp/faxout";
{
for (addr = addrlist; addr; addr = addr->next)
{
- int error = getnameinfo(&(addr->addr.addr),
- httpAddrLength(&(addr->addr)),
- fqdn, sizeof(fqdn), NULL, 0, NI_NAMEREQD);
+ int error = getnameinfo(&(addr->addr.addr), (socklen_t)httpAddrLength(&(addr->addr)), fqdn, sizeof(fqdn), NULL, 0, NI_NAMEREQD);
if (!error)
{
if ((!strcmp(scheme, "ipp") || !strcmp(scheme, "ipps")) &&
!strcmp(uribuf->resource, "/cups"))
- httpAssembleURIf(HTTP_URI_CODING_ALL, uribuf->buffer, uribuf->bufsize,
- scheme, NULL, hostTarget, ntohs(port), "%s?snmp=false",
- resource);
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uribuf->buffer, (int)uribuf->bufsize, scheme, NULL, hostTarget, ntohs(port), "%s?snmp=false", resource);
else
- httpAssembleURI(HTTP_URI_CODING_ALL, uribuf->buffer, uribuf->bufsize,
- scheme, NULL, hostTarget, ntohs(port), resource);
+ httpAssembleURI(HTTP_URI_CODING_ALL, uribuf->buffer, (int)uribuf->bufsize, scheme, NULL, hostTarget, ntohs(port), resource);
DEBUG_printf(("8http_resolve_cb: Resolved URI is \"%s\"...", uribuf->buffer));
}
return;
}
+ /*
+ * If we have a UUID, compare it...
+ */
+
+ if (uribuf->uuid && (pair = avahi_string_list_find(txt, "UUID")) != NULL)
+ {
+ char uuid[256]; /* UUID value */
+
+ avahi_string_list_get_pair(pair, NULL, &value, &valueLen);
+
+ memcpy(uuid, value, valueLen);
+ uuid[valueLen] = '\0';
+
+ if (_cups_strcasecmp(uuid, uribuf->uuid))
+ {
+ if (uribuf->options & _HTTP_RESOLVE_STDERR)
+ fprintf(stderr, "DEBUG: Found UUID %s, looking for %s.", uuid,
+ uribuf->uuid);
+
+ DEBUG_printf(("7http_resolve_cb: Found UUID %s, looking for %s.", uuid,
+ uribuf->uuid));
+ return;
+ }
+ }
+
/*
* Figure out the scheme from the full name...
*/
*/
if ((uribuf->options & _HTTP_RESOLVE_FAXOUT) &&
- (!strcmp(scheme, "ipp") || !strcmp(scheme, "ipps")))
+ (!strcmp(scheme, "ipp") || !strcmp(scheme, "ipps")) &&
+ !avahi_string_list_find(txt, "printer-type"))
{
reskey = "rfo";
resdefault = "/ipp/faxout";
{
for (addr = addrlist; addr; addr = addr->next)
{
- int error = getnameinfo(&(addr->addr.addr),
- httpAddrLength(&(addr->addr)),
- fqdn, sizeof(fqdn), NULL, 0, NI_NAMEREQD);
+ int error = getnameinfo(&(addr->addr.addr), (socklen_t)httpAddrLength(&(addr->addr)), fqdn, sizeof(fqdn), NULL, 0, NI_NAMEREQD);
if (!error)
{
/*
- * End of "$Id: http-support.c 7952 2008-09-17 00:56:20Z mike $".
+ * End of "$Id$".
*/