Lines Matching +full:data +full:- +full:uri +full:- +full:to +full:- +full:buffer
4 * Copyright 2007-2019 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
15 #include "cups-private.h"
16 #include "debug-internal.h"
27 # include <avahi-client/client.h>
28 # include <avahi-client/lookup.h>
29 # include <avahi-common/simple-watch.h>
37 typedef struct _http_uribuf_s /* URI buffer */
42 char *buffer; /* Pointer to buffer */ member
43 size_t bufsize; /* Size of buffer */
44 int options; /* Options passed to _httpResolveURI */
45 const char *resource; /* Resource from URI */
46 const char *uuid; /* UUID from URI */
141 * 'httpAssembleURI()' - Assemble a uniform resource identifier from its
144 * This function escapes reserved characters in the URI depending on the
146 * place of traditional string functions whenever you need to create a
147 * URI string.
152 http_uri_status_t /* O - URI status */
154 http_uri_coding_t encoding, /* I - Encoding flags */ in httpAssembleURI()
155 char *uri, /* I - URI buffer */ in httpAssembleURI() argument
156 int urilen, /* I - Size of URI buffer */ in httpAssembleURI()
157 const char *scheme, /* I - Scheme name */ in httpAssembleURI()
158 const char *username, /* I - Username */ in httpAssembleURI()
159 const char *host, /* I - Hostname or address */ in httpAssembleURI()
160 int port, /* I - Port number */ in httpAssembleURI()
161 const char *resource) /* I - Resource */ in httpAssembleURI()
163 char *ptr, /* Pointer into URI buffer */ in httpAssembleURI()
164 *end; /* End of URI buffer */ in httpAssembleURI()
171 if (!uri || urilen < 1 || !scheme || port < 0) in httpAssembleURI()
173 if (uri) in httpAssembleURI()
174 *uri = '\0'; in httpAssembleURI()
180 * Assemble the URI starting with the scheme... in httpAssembleURI()
183 end = uri + urilen - 1; in httpAssembleURI()
184 ptr = http_copy_encode(uri, scheme, end, NULL, NULL, 0); in httpAssembleURI()
244 * Then add the hostname. Since IPv6 is a particular pain to deal in httpAssembleURI()
245 * with, we have several special cases to deal with. If we get in httpAssembleURI()
247 * URI format. Since DNS-SD service names can sometimes look like in httpAssembleURI()
271 * We have a link-local address, add "[v1." prefix... in httpAssembleURI()
287 * We have a normal (or RFC 6874 link-local) address, add "[" prefix... in httpAssembleURI()
310 if (ptr >= (end - 2)) in httpAssembleURI()
338 * "reg-name" ABNF rule; anything <= SP or >= DEL plus % gets automatically in httpAssembleURI()
339 * percent-encoded. in httpAssembleURI()
355 snprintf(ptr, (size_t)(end - ptr + 1), ":%d", port); in httpAssembleURI()
369 char *query; /* Pointer to query string */ in httpAssembleURI()
373 * Copy the resource string up to the query string if present... in httpAssembleURI()
400 * Nul-terminate the URI buffer and return with no errors... in httpAssembleURI()
408 * Clear the URI string and return an overflow error; I don't usually in httpAssembleURI()
414 *uri = '\0'; in httpAssembleURI()
420 * 'httpAssembleURIf()' - Assemble a uniform resource identifier from its
424 * argument "resourcef" and escapes reserved characters in the URI
427 * you need to create a URI string.
432 http_uri_status_t /* O - URI status */
434 http_uri_coding_t encoding, /* I - Encoding flags */ in httpAssembleURIf()
435 char *uri, /* I - URI buffer */ in httpAssembleURIf() argument
436 int urilen, /* I - Size of URI buffer */ in httpAssembleURIf()
437 const char *scheme, /* I - Scheme name */ in httpAssembleURIf()
438 const char *username, /* I - Username */ in httpAssembleURIf()
439 const char *host, /* I - Hostname or address */ in httpAssembleURIf()
440 int port, /* I - Port number */ in httpAssembleURIf()
441 const char *resourcef, /* I - Printf-style resource */ in httpAssembleURIf()
442 ...) /* I - Additional arguments as needed */ in httpAssembleURIf()
444 va_list ap; /* Pointer to additional arguments */ in httpAssembleURIf()
453 if (!uri || urilen < 1 || !scheme || port < 0 || !resourcef) in httpAssembleURIf()
455 if (uri) in httpAssembleURIf()
456 *uri = '\0'; in httpAssembleURIf()
462 * Format the resource string and assemble the URI... in httpAssembleURIf()
471 *uri = '\0'; in httpAssembleURIf()
475 return (httpAssembleURI(encoding, uri, urilen, scheme, username, host, in httpAssembleURIf()
481 * 'httpAssembleUUID()' - Assemble a name-based UUID URN conforming to RFC 4122.
483 * This function creates a unique 128-bit identifying number using the server
484 * name, port number, random data, and optionally an object name and/or object
487 * The buffer needs to be at least 46 bytes in size.
492 char * /* I - UUID string */
493 httpAssembleUUID(const char *server, /* I - Server name */ in httpAssembleUUID()
494 int port, /* I - Port number */ in httpAssembleUUID()
495 const char *name, /* I - Object name or NULL */ in httpAssembleUUID()
496 int number, /* I - Object number or 0 */ in httpAssembleUUID()
497 char *buffer, /* I - String buffer */ in httpAssembleUUID() argument
498 size_t bufsize) /* I - Size of buffer */ in httpAssembleUUID()
500 char data[1024]; /* Source string for MD5 */ in httpAssembleUUID() local
505 * Build a version 3 UUID conforming to RFC 4122. in httpAssembleUUID()
508 * number, and some random data on the end. in httpAssembleUUID()
511 snprintf(data, sizeof(data), "%s:%d:%s:%d:%04x:%04x", server, in httpAssembleUUID()
515 cupsHashData("md5", (unsigned char *)data, strlen(data), md5sum, sizeof(md5sum)); in httpAssembleUUID()
521 snprintf(buffer, bufsize, in httpAssembleUUID()
522 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" in httpAssembleUUID()
529 return (buffer); in httpAssembleUUID()
534 * 'httpDecode64()' - Base64-decode a string.
537 * which provides buffer length arguments.
542 char * /* O - Decoded string */
543 httpDecode64(char *out, /* I - String to write to */ in httpDecode64()
544 const char *in) /* I - String to read from */ in httpDecode64()
546 int outlen; /* Output buffer length */ in httpDecode64()
550 * Use the old maximum buffer size for binary compatibility... in httpDecode64()
560 * 'httpDecode64_2()' - Base64-decode a string.
562 * The caller must initialize "outlen" to the maximum size of the decoded
569 char * /* O - Decoded string */
570 httpDecode64_2(char *out, /* I - String to write to */ in httpDecode64_2()
571 int *outlen, /* IO - Size of output string */ in httpDecode64_2()
572 const char *in) /* I - String to read from */ in httpDecode64_2()
577 *outend; /* End of output buffer */ in httpDecode64_2()
596 * Convert from base-64 to bytes... in httpDecode64_2()
599 for (outptr = out, outend = out + *outlen - 1, pos = 0; *in != '\0'; in ++) in httpDecode64_2()
602 * Decode this character into a number from 0 to 63... in httpDecode64_2()
606 base64 = (unsigned)(*in - 'A'); in httpDecode64_2()
608 base64 = (unsigned)(*in - 'a' + 26); in httpDecode64_2()
610 base64 = (unsigned)(*in - '0' + 52); in httpDecode64_2()
659 *outlen = (int)(outptr - out); in httpDecode64_2()
666 * 'httpEncode64()' - Base64-encode a string.
669 * which provides buffer length arguments.
674 char * /* O - Encoded string */
675 httpEncode64(char *out, /* I - String to write to */ in httpEncode64()
676 const char *in) /* I - String to read from */ in httpEncode64()
683 * 'httpEncode64_2()' - Base64-encode a string.
688 char * /* O - Encoded string */
689 httpEncode64_2(char *out, /* I - String to write to */ in httpEncode64_2()
690 int outlen, /* I - Maximum size of output string */ in httpEncode64_2()
691 const char *in, /* I - String to read from */ in httpEncode64_2()
692 int inlen) /* I - Size of input string */ in httpEncode64_2()
695 *outend; /* End of output buffer */ in httpEncode64_2()
713 * Convert bytes to base-64... in httpEncode64_2()
716 for (outptr = out, outend = out + outlen - 1; inlen > 0; in ++, inlen --) in httpEncode64_2()
719 * Encode the up to 3 characters as 4 Base64 numbers... in httpEncode64_2()
734 inlen --; in httpEncode64_2()
753 inlen --; in httpEncode64_2()
776 * 'httpGetDateString()' - Get a formatted date/time string from a time value.
781 const char * /* O - Date/time string */
782 httpGetDateString(time_t t) /* I - Time in seconds */ in httpGetDateString()
784 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ in httpGetDateString()
787 return (httpGetDateString2(t, cg->http_date, sizeof(cg->http_date))); in httpGetDateString()
792 * 'httpGetDateString2()' - Get a formatted date/time string from a time value.
797 const char * /* O - Date/time string */
798 httpGetDateString2(time_t t, /* I - Time in seconds */ in httpGetDateString2()
799 char *s, /* I - String buffer */ in httpGetDateString2()
800 int slen) /* I - Size of string buffer */ in httpGetDateString2()
802 struct tm tdate; /* UNIX date/time data */ in httpGetDateString2()
814 * 'httpGetDateTime()' - Get a time value from a formatted date/time string.
817 time_t /* O - Time in seconds */
818 httpGetDateTime(const char *s) /* I - Date/time string */ in httpGetDateTime()
825 static const int normal_days[] = /* Days to a month, normal years */ in httpGetDateTime()
827 static const int leap_days[] = /* Days to a month, leap years */ in httpGetDateTime()
851 * Convert the month name to a number from 0 to 11. in httpGetDateTime()
864 * Now convert the date and time to a UNIX time value in seconds since in httpGetDateTime()
870 days = leap_days[i] + day - 1; in httpGetDateTime()
872 days = normal_days[i] + day - 1; in httpGetDateTime()
876 days += (year - 1970) * 365 + /* 365 days per year (normally) */ in httpGetDateTime()
877 ((year - 1) / 4 - 492) - /* + leap days */ in httpGetDateTime()
878 ((year - 1) / 100 - 19) + /* - 100 year days */ in httpGetDateTime()
879 ((year - 1) / 400 - 4); /* + 400 year days */ in httpGetDateTime()
888 * 'httpSeparate()' - Separate a Universal Resource Identifier into its
897 httpSeparate(const char *uri, /* I - Universal Resource Identifier */ in httpSeparate() argument
898 char *scheme, /* O - Scheme [32] (http, https, etc.) */ in httpSeparate()
899 char *username, /* O - Username [1024] */ in httpSeparate()
900 char *host, /* O - Hostname [1024] */ in httpSeparate()
901 int *port, /* O - Port number to use */ in httpSeparate()
902 char *resource) /* O - Resource/filename [1024] */ in httpSeparate()
904 httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, 32, username, in httpSeparate()
911 * 'httpSeparate2()' - Separate a Universal Resource Identifier into its
921 httpSeparate2(const char *uri, /* I - Universal Resource Identifier */ in httpSeparate2() argument
922 char *scheme, /* O - Scheme (http, https, etc.) */ in httpSeparate2()
923 int schemelen, /* I - Size of scheme buffer */ in httpSeparate2()
924 char *username, /* O - Username */ in httpSeparate2()
925 int usernamelen, /* I - Size of username buffer */ in httpSeparate2()
926 char *host, /* O - Hostname */ in httpSeparate2()
927 int hostlen, /* I - Size of hostname buffer */ in httpSeparate2()
928 int *port, /* O - Port number to use */ in httpSeparate2()
929 char *resource, /* O - Resource/filename */ in httpSeparate2()
930 int resourcelen) /* I - Size of resource buffer */ in httpSeparate2()
932 httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, schemelen, username, in httpSeparate2()
938 * 'httpSeparateURI()' - Separate a Universal Resource Identifier into its
944 http_uri_status_t /* O - Result of separation */
946 http_uri_coding_t decoding, /* I - Decoding flags */ in httpSeparateURI()
947 const char *uri, /* I - Universal Resource Identifier */ in httpSeparateURI() argument
948 char *scheme, /* O - Scheme (http, https, etc.) */ in httpSeparateURI()
949 int schemelen, /* I - Size of scheme buffer */ in httpSeparateURI()
950 char *username, /* O - Username */ in httpSeparateURI()
951 int usernamelen, /* I - Size of username buffer */ in httpSeparateURI()
952 char *host, /* O - Hostname */ in httpSeparateURI()
953 int hostlen, /* I - Size of hostname buffer */ in httpSeparateURI()
954 int *port, /* O - Port number to use */ in httpSeparateURI()
955 char *resource, /* O - Resource/filename */ in httpSeparateURI()
956 int resourcelen) /* I - Size of resource buffer */ in httpSeparateURI()
965 * Initialize everything to blank... in httpSeparateURI()
987 if (!uri || !port || !scheme || schemelen <= 0 || !username || in httpSeparateURI()
992 if (!*uri) in httpSeparateURI()
996 * Grab the scheme portion of the URI... in httpSeparateURI()
1001 if (!strncmp(uri, "//", 2)) in httpSeparateURI()
1010 else if (*uri == '/') in httpSeparateURI()
1022 * Standard URI with scheme... in httpSeparateURI()
1025 for (ptr = scheme, end = scheme + schemelen - 1; in httpSeparateURI()
1026 *uri && *uri != ':' && ptr < end;) in httpSeparateURI()
1029 "0123456789-+.", *uri) != NULL) in httpSeparateURI()
1030 *ptr++ = *uri++; in httpSeparateURI()
1036 if (*uri != ':' || *scheme == '.' || !*scheme) in httpSeparateURI()
1042 uri ++; in httpSeparateURI()
1066 if (!strncmp(uri, "//", 2)) in httpSeparateURI()
1072 uri += 2; in httpSeparateURI()
1078 if ((sep = strpbrk(uri, "@/")) != NULL && *sep == '@') in httpSeparateURI()
1084 uri = http_copy_decode(username, uri, usernamelen, "@", in httpSeparateURI()
1087 if (!uri) in httpSeparateURI()
1093 uri ++; in httpSeparateURI()
1100 if (*uri == '[') in httpSeparateURI()
1106 uri ++; in httpSeparateURI()
1107 if (*uri == 'v') in httpSeparateURI()
1113 uri ++; in httpSeparateURI()
1115 while (isxdigit(*uri & 255)) in httpSeparateURI()
1116 uri ++; in httpSeparateURI()
1118 if (*uri != '.') in httpSeparateURI()
1124 uri ++; in httpSeparateURI()
1127 uri = http_copy_decode(host, uri, hostlen, "]", in httpSeparateURI()
1130 if (!uri) in httpSeparateURI()
1140 if (*uri != ']') in httpSeparateURI()
1146 uri ++; in httpSeparateURI()
1152 * Convert zone separator to % and stop here... in httpSeparateURI()
1178 for (ptr = (char *)uri; *ptr; ptr ++) in httpSeparateURI()
1184 "-._~" /* unreserved */ in httpSeparateURI()
1185 "%" /* pct-encoded */ in httpSeparateURI()
1186 "!$&'()*+,;=" /* sub-delims */ in httpSeparateURI()
1194 * Then copy the hostname or IPv4 address to the buffer... in httpSeparateURI()
1197 uri = http_copy_decode(host, uri, hostlen, ":?/", in httpSeparateURI()
1200 if (!uri) in httpSeparateURI()
1208 * Validate hostname for file scheme - only empty and localhost are in httpSeparateURI()
1222 if (*uri == ':') in httpSeparateURI()
1228 if (!isdigit(uri[1] & 255)) in httpSeparateURI()
1234 *port = (int)strtol(uri + 1, (char **)&uri, 10); in httpSeparateURI()
1242 if (*uri != '/' && *uri) in httpSeparateURI()
1254 if (*uri == '?' || !*uri) in httpSeparateURI()
1267 if (*uri == '?') in httpSeparateURI()
1268 uri = http_copy_decode(resource + 1, uri, resourcelen - 1, NULL, in httpSeparateURI()
1275 uri = http_copy_decode(resource, uri, resourcelen, "?", in httpSeparateURI()
1278 if (uri && *uri == '?') in httpSeparateURI()
1286 uri = http_copy_decode(resptr, uri, in httpSeparateURI()
1287 resourcelen - (int)(resptr - resource), NULL, in httpSeparateURI()
1292 if (!uri) in httpSeparateURI()
1299 * Return the URI separation status... in httpSeparateURI()
1307 * '_httpSetDigestAuthString()' - Calculate a Digest authentication response
1312 int /* O - 1 on success, 0 on failure */
1314 http_t *http, /* I - HTTP connection */ in _httpSetDigestAuthString()
1315 const char *nonce, /* I - Nonce value */ in _httpSetDigestAuthString()
1316 const char *method, /* I - HTTP method */ in _httpSetDigestAuthString()
1317 const char *resource) /* I - HTTP resource path */ in _httpSetDigestAuthString()
1319 char kd[65], /* Final MD5/SHA-256 digest */ in _httpSetDigestAuthString()
1321 ha2[65], /* Hash of method:request-uri */ in _httpSetDigestAuthString()
1324 *password, /* Pointer to password */ in _httpSetDigestAuthString()
1326 digest[1024]; /* Digest auth data */ in _httpSetDigestAuthString()
1327 unsigned char hash[32]; /* Hash buffer */ in _httpSetDigestAuthString()
1329 _cups_globals_t *cg = _cupsGlobals(); /* Per-thread globals */ in _httpSetDigestAuthString()
1334 if (nonce && *nonce && strcmp(nonce, http->nonce)) in _httpSetDigestAuthString()
1336 strlcpy(http->nonce, nonce, sizeof(http->nonce)); in _httpSetDigestAuthString()
1338 if (nonce == http->nextnonce) in _httpSetDigestAuthString()
1339 http->nextnonce[0] = '\0'; in _httpSetDigestAuthString()
1341 http->nonce_count = 1; in _httpSetDigestAuthString()
1344 http->nonce_count ++; in _httpSetDigestAuthString()
1346 strlcpy(username, http->userpass, sizeof(username)); in _httpSetDigestAuthString()
1352 if (http->algorithm[0]) in _httpSetDigestAuthString()
1366 if (!_cups_strcasecmp(http->algorithm, "MD5")) in _httpSetDigestAuthString()
1372 if (cg->digestoptions == _CUPS_DIGESTOPTIONS_DENYMD5) in _httpSetDigestAuthString()
1380 else if (!_cups_strcasecmp(http->algorithm, "SHA-256")) in _httpSetDigestAuthString()
1383 * RFC 7616 Digest with SHA-256 in _httpSetDigestAuthString()
1386 hashalg = "sha2-256"; in _httpSetDigestAuthString()
1402 snprintf(temp, sizeof(temp), "%s:%s:%s", username, http->realm, password); in _httpSetDigestAuthString()
1406 /* H(A2) = H(method:uri) */ in _httpSetDigestAuthString()
1412 …snprintf(temp, sizeof(temp), "%s:%s:%08x:%s:%s:%s", ha1, http->nonce, http->nonce_count, cnonce, "… in _httpSetDigestAuthString()
1417 * Pass the RFC 2617/7616 WWW-Authenticate header... in _httpSetDigestAuthString()
1420 if (http->opaque[0]) in _httpSetDigestAuthString()
1421 …ce=\"%s\", nc=%08x, uri=\"%s\", response=\"%s\"", cupsUser(), http->realm, http->nonce, http->algo… in _httpSetDigestAuthString()
1423 …th, cnonce=\"%s\", nc=%08x, uri=\"%s\", response=\"%s\"", username, http->realm, http->nonce, http… in _httpSetDigestAuthString()
1432 snprintf(temp, sizeof(temp), "%s:%s:%s", username, http->realm, password); in _httpSetDigestAuthString()
1436 /* H(A2) = H(method:uri) */ in _httpSetDigestAuthString()
1442 snprintf(temp, sizeof(temp), "%s:%s:%s", ha1, http->nonce, ha2); in _httpSetDigestAuthString()
1447 * Pass the old RFC 2069 WWW-Authenticate header... in _httpSetDigestAuthString()
1450 … "username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", response=\"%s\"", username, http->realm… in _httpSetDigestAuthString()
1460 * 'httpStateString()' - Return the string describing a HTTP state value.
1465 const char * /* O - State string */
1466 httpStateString(http_state_t state) /* I - HTTP state value */ in httpStateString()
1471 return (http_states[state - HTTP_STATE_ERROR]); in httpStateString()
1476 * '_httpStatus()' - Return the localized string describing a HTTP status code.
1481 const char * /* O - Localized status string */
1482 _httpStatus(cups_lang_t *lang, /* I - Language */ in _httpStatus()
1483 http_status_t status) /* I - HTTP status code */ in _httpStatus()
1540 s = _("URI Too Long"); in _httpStatus()
1577 * 'httpStatus()' - Return a short string describing a HTTP status code.
1579 * The returned string is localized to the current POSIX locale and is based
1583 const char * /* O - Localized status string */
1584 httpStatus(http_status_t status) /* I - HTTP status code */ in httpStatus()
1586 _cups_globals_t *cg = _cupsGlobals(); /* Global data */ in httpStatus()
1589 if (!cg->lang_default) in httpStatus()
1590 cg->lang_default = cupsLangDefault(); in httpStatus()
1592 return (_httpStatus(cg->lang_default, status)); in httpStatus()
1596 * 'httpURIStatusString()' - Return a string describing a URI status code.
1601 const char * /* O - Localized status string */
1603 http_uri_status_t status) /* I - URI status code */ in httpURIStatusString()
1606 _cups_globals_t *cg = _cupsGlobals(); /* Global data */ in httpURIStatusString()
1609 if (!cg->lang_default) in httpURIStatusString()
1610 cg->lang_default = cupsLangDefault(); in httpURIStatusString()
1615 s = _("URI too large"); in httpURIStatusString()
1618 s = _("Bad arguments to function"); in httpURIStatusString()
1621 s = _("Bad resource in URI"); in httpURIStatusString()
1624 s = _("Bad port number in URI"); in httpURIStatusString()
1627 s = _("Bad hostname/address in URI"); in httpURIStatusString()
1630 s = _("Bad username in URI"); in httpURIStatusString()
1633 s = _("Bad scheme in URI"); in httpURIStatusString()
1636 s = _("Bad/empty URI"); in httpURIStatusString()
1642 s = _("Missing scheme in URI"); in httpURIStatusString()
1645 s = _("Unknown scheme in URI"); in httpURIStatusString()
1648 s = _("Missing resource in URI"); in httpURIStatusString()
1656 return (_cupsLangString(cg->lang_default, s)); in httpURIStatusString()
1662 * '_cups_hstrerror()' - hstrerror() emulation function for Solaris and others.
1665 const char * /* O - Error string */
1666 _cups_hstrerror(int error) /* I - Error number */ in _cups_hstrerror()
1674 "No data associated with name." in _cups_hstrerror()
1687 * '_httpDecodeURI()' - Percent-decode a HTTP request URI.
1690 char * /* O - Decoded URI or NULL on error */
1691 _httpDecodeURI(char *dst, /* I - Destination buffer */ in _httpDecodeURI()
1692 const char *src, /* I - Source URI */ in _httpDecodeURI()
1693 size_t dstsize) /* I - Size of destination buffer */ in _httpDecodeURI()
1703 * '_httpEncodeURI()' - Percent-encode a HTTP request URI.
1706 char * /* O - Encoded URI */
1707 _httpEncodeURI(char *dst, /* I - Destination buffer */ in _httpEncodeURI()
1708 const char *src, /* I - Source URI */ in _httpEncodeURI()
1709 size_t dstsize) /* I - Size of destination buffer */ in _httpEncodeURI()
1711 http_copy_encode(dst, src, dst + dstsize - 1, NULL, NULL, 1); in _httpEncodeURI()
1717 * '_httpResolveURI()' - Resolve a DNS-SD URI.
1720 const char * /* O - Resolved URI */
1722 const char *uri, /* I - DNS-SD URI */ in _httpResolveURI() argument
1723 char *resolved_uri, /* I - Buffer for resolved URI */ in _httpResolveURI()
1724 size_t resolved_size, /* I - Size of URI buffer */ in _httpResolveURI()
1725 int options, /* I - Resolve options */ in _httpResolveURI()
1726 int (*cb)(void *context), /* I - Continue callback function */ in _httpResolveURI()
1727 void *context) /* I - Context pointer for callback */ in _httpResolveURI()
1729 char scheme[32], /* URI components... */ in _httpResolveURI()
1735 http_uri_status_t status; /* URI decode status */ in _httpResolveURI()
1739 …UG_printf(("_httpResolveURI(uri=\"%s\", resolved_uri=%p, resolved_size=" CUPS_LLFMT ", options=0x%… in _httpResolveURI()
1742 * Get the device URI... in _httpResolveURI()
1746 if ((status = httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, in _httpResolveURI()
1751 if (httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, in _httpResolveURI()
1758 _cupsLangPrintFilter(stderr, "ERROR", _("Bad device-uri \"%s\"."), uri); in _httpResolveURI()
1772 char *regtype, /* Pointer to type in hostname */ in _httpResolveURI()
1773 *domain, /* Pointer to domain in hostname */ in _httpResolveURI()
1774 *uuid, /* Pointer to UUID in URI */ in _httpResolveURI()
1775 *uuidend; /* Pointer to end of UUID in URI */ in _httpResolveURI()
1776 _http_uribuf_t uribuf; /* URI buffer */ in _httpResolveURI()
1777 int offline = 0; /* offline-report state set? */ in _httpResolveURI()
1779 DNSServiceRef ref, /* DNS-SD master service reference */ in _httpResolveURI()
1780 domainref = NULL,/* DNS-SD service reference for domain */ in _httpResolveURI()
1781 ippref = NULL, /* DNS-SD service reference for network IPP */ in _httpResolveURI()
1782 ippsref = NULL, /* DNS-SD service reference for network IPPS */ in _httpResolveURI()
1783 localref; /* DNS-SD service reference for .local */ in _httpResolveURI()
1786 struct pollfd polldata; /* Polling data */ in _httpResolveURI()
1803 for (regtype = strstr(hostname, "._tcp") - 2; in _httpResolveURI()
1805 regtype --) in _httpResolveURI()
1841 uribuf.buffer = resolved_uri; in _httpResolveURI()
1851 fputs("STATE: +connecting-to-device\n", stderr); in _httpResolveURI()
1856 uri = NULL; in _httpResolveURI()
1891 * Wakeup every 2 seconds to emit a "looking for printer" message... in _httpResolveURI()
1894 if ((timeout = end_time - time(NULL)) > 2) in _httpResolveURI()
1929 * Wait 2 seconds for a response to the local resolve; if nothing in _httpResolveURI()
1977 * If it hasn't resolved within 5 seconds set the offline-report in _httpResolveURI()
1978 * printer-state-reason... in _httpResolveURI()
1984 fputs("STATE: +offline-report\n", stderr); in _httpResolveURI()
1993 uri = resolved_uri; in _httpResolveURI()
2056 * If it hasn't resolved within 5 seconds set the offline-report in _httpResolveURI()
2057 * printer-state-reason... in _httpResolveURI()
2063 fputs("STATE: +offline-report\n", stderr); in _httpResolveURI()
2073 uri = resolved_uri; in _httpResolveURI()
2085 if (uri) in _httpResolveURI()
2087 fprintf(stderr, "DEBUG: Resolved as \"%s\"...\n", uri); in _httpResolveURI()
2088 fputs("STATE: -connecting-to-device,offline-report\n", stderr); in _httpResolveURI()
2092 fputs("DEBUG: Unable to resolve URI\n", stderr); in _httpResolveURI()
2093 fputs("STATE: -connecting-to-device\n", stderr); in _httpResolveURI()
2099 * No DNS-SD support... in _httpResolveURI()
2102 uri = NULL; in _httpResolveURI()
2105 if ((options & _HTTP_RESOLVE_STDERR) && !uri) in _httpResolveURI()
2106 _cupsLangPrintFilter(stderr, "INFO", _("Unable to find printer.")); in _httpResolveURI()
2111 * Nothing more to do... in _httpResolveURI()
2114 strlcpy(resolved_uri, uri, resolved_size); in _httpResolveURI()
2115 uri = resolved_uri; in _httpResolveURI()
2118 DEBUG_printf(("2_httpResolveURI: Returning \"%s\"", uri)); in _httpResolveURI()
2120 return (uri); in _httpResolveURI()
2126 * 'http_client_cb()' - Client callback for resolving URI.
2131 AvahiClient *client, /* I - Client information */ in http_client_cb()
2132 AvahiClientState state, /* I - Current state */ in http_client_cb()
2133 void *context) /* I - Pointer to URI buffer */ in http_client_cb()
2145 /* URI buffer */ in http_client_cb()
2147 avahi_simple_poll_quit(uribuf->poll); in http_client_cb()
2154 * 'http_copy_decode()' - Copy and decode a URI.
2157 static const char * /* O - New source pointer or NULL on error */
2158 http_copy_decode(char *dst, /* O - Destination buffer */ in http_copy_decode()
2159 const char *src, /* I - Source pointer */ in http_copy_decode()
2160 int dstsize, /* I - Destination size */ in http_copy_decode()
2161 const char *term, /* I - Terminating characters */ in http_copy_decode()
2162 int decode) /* I - Decode %-encoded values */ in http_copy_decode()
2164 char *ptr, /* Pointer into buffer */ in http_copy_decode()
2165 *end; /* End of buffer */ in http_copy_decode()
2170 * Copy the src to the destination until we hit a terminating character in http_copy_decode()
2174 for (ptr = dst, end = dst + dstsize - 1; in http_copy_decode()
2184 * Grab a hex-encoded character... in http_copy_decode()
2189 quoted = (tolower(*src) - 'a' + 10) << 4; in http_copy_decode()
2191 quoted = (*src - '0') << 4; in http_copy_decode()
2195 quoted |= tolower(*src) - 'a' + 10; in http_copy_decode()
2197 quoted |= *src - '0'; in http_copy_decode()
2204 * Bad hex-encoded character... in http_copy_decode()
2227 * 'http_copy_encode()' - Copy and encode a URI.
2230 static char * /* O - End of current URI */
2231 http_copy_encode(char *dst, /* O - Destination buffer */ in http_copy_encode()
2232 const char *src, /* I - Source pointer */ in http_copy_encode()
2233 char *dstend, /* I - End of destination buffer */ in http_copy_encode()
2234 const char *reserved, /* I - Extra reserved characters */ in http_copy_encode()
2235 const char *term, /* I - Terminating characters */ in http_copy_encode()
2236 int encode) /* I - %-encode reserved chars? */ in http_copy_encode()
2277 * 'http_resolve_cb()' - Build a device URI for the given service name.
2282 DNSServiceRef sdRef, /* I - Service reference */ in http_resolve_cb()
2283 DNSServiceFlags flags, /* I - Results flags */ in http_resolve_cb()
2284 uint32_t interfaceIndex, /* I - Interface number */ in http_resolve_cb()
2285 DNSServiceErrorType errorCode, /* I - Error, if any */ in http_resolve_cb()
2286 const char *fullName, /* I - Full service name */ in http_resolve_cb()
2287 const char *hostTarget, /* I - Hostname */ in http_resolve_cb()
2288 uint16_t port, /* I - Port number */ in http_resolve_cb()
2289 uint16_t txtLen, /* I - Length of TXT record */ in http_resolve_cb()
2290 const unsigned char *txtRecord, /* I - TXT record data */ in http_resolve_cb()
2291 void *context) /* I - Pointer to URI buffer */ in http_resolve_cb()
2294 /* URI buffer */ in http_resolve_cb()
2295 const char *scheme, /* URI scheme */ in http_resolve_cb()
2311 if (uribuf->uuid && in http_resolve_cb()
2320 if (_cups_strcasecmp(uuid, uribuf->uuid)) in http_resolve_cb()
2322 if (uribuf->options & _HTTP_RESOLVE_STDERR) in http_resolve_cb()
2324 uribuf->uuid); in http_resolve_cb()
2327 uribuf->uuid)); in http_resolve_cb()
2336 if (strstr(fullName, "._ipps") || strstr(fullName, "._ipp-tls")) in http_resolve_cb()
2338 else if (strstr(fullName, "._ipp") || strstr(fullName, "._fax-ipp")) in http_resolve_cb()
2346 else if (strstr(fullName, "._pdl-datastream.")) in http_resolve_cb()
2355 if ((uribuf->options & _HTTP_RESOLVE_FAXOUT) && in http_resolve_cb()
2357 !TXTRecordGetValuePtr(txtLen, txtRecord, "printer-type", &valueLen)) in http_resolve_cb()
2383 * Convert to resource by concatenating with a leading "/"... in http_resolve_cb()
2404 if ((uribuf->options & _HTTP_RESOLVE_FQDN) && in http_resolve_cb()
2405 (hostptr = hostTarget + strlen(hostTarget) - 7) > hostTarget && in http_resolve_cb()
2410 * getting the IP address of the .local name and then do reverse-lookups... in http_resolve_cb()
2421 for (addr = addrlist; addr; addr = addr->next) in http_resolve_cb()
2423 …int error = getnameinfo(&(addr->addr.addr), (socklen_t)httpAddrLength(&(addr->addr)), fqdn, sizeof… in http_resolve_cb()
2429 if ((hostptr = fqdn + strlen(fqdn) - 6) <= fqdn || in http_resolve_cb()
2439 httpAddrString(&(addr->addr), fqdn, sizeof(fqdn)), in http_resolve_cb()
2449 * Assemble the final device URI... in http_resolve_cb()
2453 !strcmp(uribuf->resource, "/cups")) in http_resolve_cb()
2454 …httpAssembleURIf(HTTP_URI_CODING_ALL, uribuf->buffer, (int)uribuf->bufsize, scheme, NULL, hostTarg… in http_resolve_cb()
2456 …httpAssembleURI(HTTP_URI_CODING_ALL, uribuf->buffer, (int)uribuf->bufsize, scheme, NULL, hostTarge… in http_resolve_cb()
2458 DEBUG_printf(("5http_resolve_cb: Resolved URI is \"%s\"...", uribuf->buffer)); in http_resolve_cb()
2463 * 'http_poll_cb()' - Wait for input on the specified file descriptors.
2472 static int /* O - Number of file descriptors matching */
2474 struct pollfd *pollfds, /* I - File descriptors */ in http_poll_cb()
2475 unsigned int num_pollfds, /* I - Number of file descriptors */ in http_poll_cb()
2476 int timeout, /* I - Timeout in milliseconds (used) */ in http_poll_cb()
2477 void *context) /* I - User data (unused) */ in http_poll_cb()
2487 * 'http_resolve_cb()' - Build a device URI for the given service name.
2492 AvahiServiceResolver *resolver, /* I - Resolver (unused) */ in http_resolve_cb()
2493 AvahiIfIndex interface, /* I - Interface index (unused) */ in http_resolve_cb()
2494 AvahiProtocol protocol, /* I - Network protocol (unused) */ in http_resolve_cb()
2495 AvahiResolverEvent event, /* I - Event (found, etc.) */ in http_resolve_cb()
2496 const char *name, /* I - Service name */ in http_resolve_cb()
2497 const char *type, /* I - Registration type */ in http_resolve_cb()
2498 const char *domain, /* I - Domain (unused) */ in http_resolve_cb()
2499 const char *hostTarget, /* I - Hostname */ in http_resolve_cb()
2500 const AvahiAddress *address, /* I - Address (unused) */ in http_resolve_cb()
2501 uint16_t port, /* I - Port number */ in http_resolve_cb()
2502 AvahiStringList *txt, /* I - TXT record */ in http_resolve_cb()
2503 AvahiLookupResultFlags flags, /* I - Lookup flags (unused) */ in http_resolve_cb()
2504 void *context) /* I - Pointer to URI buffer */ in http_resolve_cb()
2507 /* URI buffer */ in http_resolve_cb()
2508 const char *scheme, /* URI scheme */ in http_resolve_cb()
2529 avahi_simple_poll_quit(uribuf->poll); in http_resolve_cb()
2537 if (uribuf->uuid && (pair = avahi_string_list_find(txt, "UUID")) != NULL) in http_resolve_cb()
2546 if (_cups_strcasecmp(uuid, uribuf->uuid)) in http_resolve_cb()
2548 if (uribuf->options & _HTTP_RESOLVE_STDERR) in http_resolve_cb()
2550 uribuf->uuid); in http_resolve_cb()
2553 uribuf->uuid)); in http_resolve_cb()
2566 else if (strstr(type, "_pdl-datastream.")) in http_resolve_cb()
2571 if (!strncmp(type, "_ipps.", 6) || !strncmp(type, "_ipp-tls.", 9)) in http_resolve_cb()
2573 else if (!strncmp(type, "_ipp.", 5) || !strncmp(type, "_fax-ipp.", 9)) in http_resolve_cb()
2581 else if (!strncmp(type, "_pdl-datastream.", 16)) in http_resolve_cb()
2586 avahi_simple_poll_quit(uribuf->poll); in http_resolve_cb()
2594 if ((uribuf->options & _HTTP_RESOLVE_FAXOUT) && in http_resolve_cb()
2596 !avahi_string_list_find(txt, "printer-type")) in http_resolve_cb()
2623 * Convert to resource by concatenating with a leading "/"... in http_resolve_cb()
2644 if ((uribuf->options & _HTTP_RESOLVE_FQDN) && in http_resolve_cb()
2645 (hostptr = hostTarget + strlen(hostTarget) - 6) > hostTarget && in http_resolve_cb()
2650 * getting the IP address of the .local name and then do reverse-lookups... in http_resolve_cb()
2661 for (addr = addrlist; addr; addr = addr->next) in http_resolve_cb()
2663 …int error = getnameinfo(&(addr->addr.addr), (socklen_t)httpAddrLength(&(addr->addr)), fqdn, sizeof… in http_resolve_cb()
2669 if ((hostptr = fqdn + strlen(fqdn) - 6) <= fqdn || in http_resolve_cb()
2679 httpAddrString(&(addr->addr), fqdn, sizeof(fqdn)), in http_resolve_cb()
2689 * Assemble the final device URI using the resolved hostname... in http_resolve_cb()
2692 httpAssembleURI(HTTP_URI_CODING_ALL, uribuf->buffer, (int)uribuf->bufsize, scheme, in http_resolve_cb()
2694 DEBUG_printf(("5http_resolve_cb: Resolved URI is \"%s\".", uribuf->buffer)); in http_resolve_cb()
2696 avahi_simple_poll_quit(uribuf->poll); in http_resolve_cb()