name.c revision 2f4ffd7f5594c0464f2a872aee5ef102f6f7b10f
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * Copyright (C) 1998-2003 Internet Software Consortium.
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * Permission to use, copy, modify, and distribute this software for any
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * purpose with or without fee is hereby granted, provided that the above
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * copyright notice and this permission notice appear in all copies.
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * PERFORMANCE OF THIS SOFTWARE.
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer/* $Id: name.c,v 1.148 2005/01/10 23:43:22 marka Exp $ */
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer#define VALID_NAME(n) ISC_MAGIC_VALID(n, DNS_NAME_MAGIC)
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayertypedef enum {
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayertypedef enum {
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*32*/
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*48*/
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /*64*/
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*80*/
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*96*/
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*112*/
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*128*/
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*256*/
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayerstatic unsigned char maptolower[] = {
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer var = default; \
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * Note: If additional attributes are added that should not be set for
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * empty names, MAKE_EMPTY() must be changed so it clears them.
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * A name is "bindable" if it can be set to point to a new value, i.e.
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * name->ndata and name->length may be changed.
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer ((name->attributes & (DNS_NAMEATTR_READONLY|DNS_NAMEATTR_DYNAMIC)) \
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * Note that the name data must be a char array, not a string
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * literal, to avoid compiler warnings about discarding
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer * the const attribute of a string.
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayerstatic unsigned char root_offsets[] = { 0 };
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer/* XXXDCL make const? */
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny MayerLIBDNS_EXTERNAL_DATA dns_name_t *dns_rootname = &root;
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayerstatic unsigned char wild_ndata[] = { '\001', '*' };
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayerstatic unsigned char wild_offsets[] = { 0 };
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayer/* XXXDCL make const? */
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny MayerLIBDNS_EXTERNAL_DATA dns_name_t *dns_wildcardname = &wild;
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayerdns_fullname_hash(dns_name_t *name, isc_boolean_t case_sensitive);
48b785fe6bcc95831f962b9b3a61c0b39e339558Danny Mayerset_offsets(const dns_name_t *name, unsigned char *offsets,
return (ISC_TRUE);
return (ISC_FALSE);
return (ISC_TRUE);
return (ISC_FALSE);
return (ISC_TRUE);
n = *ndata++;
return (ISC_FALSE);
return (ISC_FALSE);
n = *ndata++;
if (first || n == 0) {
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
return (ISC_TRUE);
n = *ndata++;
if (first || n == 0) {
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
unsigned char *ndata;
return (ISC_TRUE);
return (ISC_FALSE);
unsigned char *ndata;
unsigned int count;
unsigned int label;
return (ISC_TRUE);
label++;
return (ISC_FALSE);
unsigned int length;
if (case_sensitive) {
while (length > 0) {
length--;
while (length > 0) {
c = maptolower[*s];
length--;
unsigned char *offsets;
nlabels = 0;
if (ldiff < 0)
l = l1;
l = l2;
l1--;
l2--;
if (cdiff < 0)
while (count > 0) {
if (chdiff != 0) {
goto done;
count--;
label1++;
label2++;
if (cdiff != 0) {
goto done;
nlabels++;
if (ldiff < 0)
else if (ldiff > 0)
done:
return (namereln);
int order;
unsigned int nlabels;
return (order);
unsigned int l, count;
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
while (count > 0) {
count--;
return (ISC_FALSE);
return (ISC_TRUE);
while (count > 0) {
count--;
int order;
unsigned int nlabels;
return (ISC_TRUE);
return (ISC_FALSE);
int order;
return (ISC_TRUE);
return (ISC_FALSE);
unsigned char *offsets;
unsigned int first, unsigned int n,
unsigned char *offsets;
unsigned char *offsets;
unsigned int len;
if (r->length > 0)
char *tdata;
unsigned char *offsets;
offsets[0] = 0;
n1 = 0;
n2 = 0;
vlen = 0;
digits = 0;
value = 0;
count = 0;
tbcount = 0;
bitlength = 0;
maxlength = 0;
tused = 0;
nused = 0;
labels = 0;
c = *tdata++;
tlen--;
tused++;
switch (state) {
case ft_init:
if (tlen != 0)
return (DNS_R_EMPTYLABEL);
labels++;
*ndata++ = 0;
nrem--;
nused++;
case ft_start:
ndata++;
nrem--;
nused++;
count = 0;
if (nrem == 0)
return (ISC_R_NOSPACE);
case ft_ordinary:
if (count == 0)
return (DNS_R_EMPTYLABEL);
labels++;
if (tlen == 0) {
labels++;
*ndata++ = 0;
nrem--;
nused++;
return (DNS_R_LABELTOOLONG);
count++;
CONVERTTOASCII(c);
if (downcase)
c = maptolower[(int)c];
*ndata++ = c;
nrem--;
nused++;
case ft_initialescape:
return (DNS_R_BADLABELTYPE);
case ft_escape:
return (DNS_R_LABELTOOLONG);
count++;
CONVERTTOASCII(c);
if (downcase)
c = maptolower[(int)c];
*ndata++ = c;
nrem--;
nused++;
digits = 0;
value = 0;
case ft_escdecimal:
return (DNS_R_BADESCAPE);
digits++;
return (DNS_R_BADESCAPE);
return (DNS_R_LABELTOOLONG);
count++;
if (downcase)
nrem--;
nused++;
if (!done) {
if (nrem == 0)
return (ISC_R_NOSPACE);
return (ISC_R_UNEXPECTEDEND);
labels++;
return (ISC_R_NOSPACE);
while (n1 > 0) {
while (n2 > 0) {
c = *label++;
if (downcase)
c = maptolower[(int)c];
*ndata++ = c;
n2--;
labels++;
if (n1 > 0) {
return (ISC_R_SUCCESS);
unsigned char *ndata;
char *tdata;
unsigned int labels;
if (trem == 0)
return (ISC_R_NOSPACE);
trem--;
nlen = 0;
if (trem == 0)
return (ISC_R_NOSPACE);
trem--;
nlen = 0;
labels--;
nlen--;
if (count == 0) {
while (count > 0) {
c = *ndata;
return (ISC_R_NOSPACE);
CONVERTFROMASCII(c);
*tdata++ = c;
ndata++;
nlen--;
if (trem == 0)
return (ISC_R_NOSPACE);
CONVERTFROMASCII(c);
*tdata++ = c;
ndata++;
trem--;
nlen--;
return (ISC_R_NOSPACE);
ndata++;
nlen--;
count--;
if (trem == 0)
return (ISC_R_NOSPACE);
trem--;
return (ISC_R_NOSPACE);
trem++;
return (ISC_R_SUCCESS);
unsigned char *ndata;
char *tdata;
unsigned int labels;
if (trem == 0)
return (ISC_R_NOSPACE);
trem--;
nlen = 0;
labels--;
nlen--;
if (count == 0)
while (count > 0) {
c = *ndata;
if (trem == 0)
return (ISC_R_NOSPACE);
CONVERTFROMASCII(c);
*tdata++ = c;
ndata++;
trem--;
nlen--;
return (ISC_R_NOSPACE);
ndata++;
nlen--;
count--;
if (trem == 0)
return (ISC_R_NOSPACE);
trem--;
return (ISC_R_NOSPACE);
if (omit_final_dot)
trem++;
return (ISC_R_SUCCESS);
return (ISC_R_NOSPACE);
labels--;
nlen--;
while (count > 0) {
nlen--;
count--;
return (ISC_R_SUCCESS);
unsigned char *ndata;
offset = 0;
nlabels = 0;
offset++;
if (count == 0) {
if (absolute)
unsigned char *offsets;
new_current = 0;
labels = 0;
hops = 0;
nused = 0;
cused = 0;
c = *cdata++;
current++;
if (hops == 0)
cused++;
switch (state) {
case fw_start:
labels++;
goto full;
*ndata++ = c;
return (DNS_R_BADLABELTYPE);
return (DNS_R_DISALLOWED);
return (DNS_R_BADLABELTYPE);
case fw_ordinary:
if (downcase)
c = maptolower[c];
case fw_copy:
*ndata++ = c;
case fw_newcurrent:
new_current += c;
return (DNS_R_BADPOINTER);
hops++;
return (DNS_R_TOOMANYHOPS);
if (!done)
return (ISC_R_UNEXPECTEDEND);
return (ISC_R_SUCCESS);
full:
return (DNS_R_NAMETOOLONG);
return (ISC_R_NOSPACE);
unsigned int methods;
if (gf) {
return (ISC_R_NOSPACE);
return (ISC_R_NOSPACE);
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
if (copy_prefix &&
length = 0;
prefix_length = 0;
labels = 0;
if (copy_prefix) {
if (copy_suffix) {
return (DNS_R_NAMETOOLONG);
return (ISC_R_NOSPACE);
if (copy_suffix) {
if (absolute)
return (ISC_R_SUCCESS);
unsigned int splitlabel;
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
isc_region_t r;
return (result);
isc_buffer_t b;
isc_region_t r;
isc_buffer_init(&b, t, sizeof(t));
return (result);
isc_buffer_usedregion(&b, &r);
return (ISC_R_SUCCESS);
isc_region_t r;
unsigned char *ndata;
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);