From e22d03eb45fdc504bca3d6227725d45a3ff7d192 Mon Sep 17 00:00:00 2001 From: Brian Wellington Date: Fri, 20 Aug 1999 17:01:06 +0000 Subject: [PATCH] Added dns_name_downcase --- lib/dns/include/dns/name.h | 10 ++++++++ lib/dns/name.c | 47 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/lib/dns/include/dns/name.h b/lib/dns/include/dns/name.h index d9d9f1f1f5..df9d43a541 100644 --- a/lib/dns/include/dns/name.h +++ b/lib/dns/include/dns/name.h @@ -789,6 +789,16 @@ dns_result_t dns_name_totext(dns_name_t *name, * DNS_R_NOSPACE */ +void +dns_name_downcase(dns_name_t *name); +/* + * Convert all uppercase letters in name to lowercase. + * + * Requires: + * + * 'name' is a valid name that is not read-only. + */ + dns_result_t dns_name_concatenate(dns_name_t *prefix, dns_name_t *suffix, dns_name_t *name, isc_buffer_t *target); /* diff --git a/lib/dns/name.c b/lib/dns/name.c index 2dbcb1b200..4079080002 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -1724,6 +1724,53 @@ dns_name_totext(dns_name_t *name, isc_boolean_t omit_final_dot, return (DNS_R_SUCCESS); } +void +dns_name_downcase(dns_name_t *name) { + unsigned char *ndata; + unsigned int nlen, count, bytes, labels; + + REQUIRE(VALID_NAME(name)); + REQUIRE((name->attributes & DNS_NAMEATTR_READONLY) == 0); + + ndata = name->ndata; + nlen = name->length; + labels = name->labels; + + while (labels > 0 && nlen > 0) { + labels--; + count = *ndata++; + nlen--; + if (count < 64) { + INSIST(nlen >= count); + while (count > 0) { + *ndata = maptolower[(*ndata)]; + ndata++; + nlen--; + count--; + } + } else if (count == DNS_LABELTYPE_BITSTRING) { + INSIST(nlen > 0); + count = *ndata++; + if (count == 0) + count = 256; + nlen--; + + bytes = count / 8; + if (count % 8 != 0) + bytes++; + INSIST(nlen >= bytes); + + /* Skip this label */ + nlen -= bytes; + ndata += bytes; + } else { + FATAL_ERROR(__FILE__, __LINE__, + "Unexpected label type %02x", count); + /* Does not return. */ + } + } +} + static void set_offsets(dns_name_t *name, unsigned char *offsets, isc_boolean_t set_labels, isc_boolean_t set_length, isc_boolean_t set_absolute)