hinfo treatment.

git-svn-id: file:///svn/unbound/trunk@510 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2007-08-13 11:53:24 +00:00
parent 2157540f35
commit 0374d468c8
2 changed files with 51 additions and 0 deletions

View file

@ -2,6 +2,7 @@
- fixup makefile, if lexer is missing give nice error and do not
mess up the dependencies.
- canonical compare routine updated.
- canonical hinfo compare.
10 August 2007: Wouter
- malloc and free overrides that track total allocation and frees.

View file

@ -446,6 +446,55 @@ struct canon_rr {
size_t rr_idx;
};
/**
* Compare HINFO rrsets. For them, the string length bytes are not lowercased,
* but the string contents are lowercased.
*
* This routine works for any 'all STR' RR type. It works similar to the
* compare_byfield routine, but stripped down, and modified to lowercase
* STR fields.
*
* @param d: rrset data
* @param i: first RR to compare
* @param j: first RR to compare
* @return comparison code.
*/
static int
canonical_compare_hinfo(struct packed_rrset_data* d, size_t i, size_t j)
{
uint8_t* di = d->rr_data[i]+2; /* ptr to current rdata byte */
uint8_t* dj = d->rr_data[j]+2;
size_t ilen = d->rr_len[i]-2; /* length left in rdata */
size_t jlen = d->rr_len[j]-2;
size_t strlen_i = 0;
size_t strlen_j = 0;
while(ilen > 0 && jlen > 0) {
/* compare this pair of bytes */
if( ((strlen_i)?(uint8_t)tolower((int)*di++):*di++)
!= ((strlen_j)?(uint8_t)tolower((int)*dj++):*dj++)
) {
if(((strlen_i)?(uint8_t)tolower((int)*di++):*di++)
< ((strlen_j)?(uint8_t)tolower((int)*dj++):*dj++))
return -1;
return 1;
}
ilen --;
jlen --;
/* read length byte of the string in rdata if strlen=0 */
if(strlen_i == 0) {
strlen_i = (size_t)di[-1];
} else strlen_i--;
if(strlen_j == 0) {
strlen_j = (size_t)dj[-1];
} else strlen_j--;
}
if(ilen == 0 && jlen == 0)
return 0;
if(ilen == 0)
return -1;
return 1;
}
/**
* Compare two RR for canonical order, in a field-style sweep.
* @param d: rrset data
@ -650,6 +699,7 @@ canonical_compare(struct ub_packed_rrset_key* rrset, size_t i, size_t j)
/* This RR type is special, as the contents of text fields
* is lowercased. */
case LDNS_RR_TYPE_HINFO:
return canonical_compare_hinfo(d, i, j);
default:
/* For unknown RR types, or types not listed above,