move get_domain logic into an action on the domain parser

This commit is contained in:
Sven M. Hallberg 2013-01-16 16:08:30 +01:00
parent 16b1e02baa
commit 0083031d6f
3 changed files with 35 additions and 26 deletions

View file

@ -43,30 +43,9 @@ bool validate_dns(HParseResult *p) {
}
char* get_domain(const HParsedToken *t) {
switch(t->token_type) {
case TT_UINT:
return " ";
case TT_SEQUENCE:
{
// Sequence of subdomains separated by "."
// Each subdomain is a label, which can be no more than 63 chars.
char *ret = h_arena_malloc(t->seq->arena, 64*t->seq->used);
size_t count = 0;
for (size_t i=0; i<t->seq->used; ++i) {
HParsedToken *tmp = t->seq->elements[i];
for (size_t j=0; j<tmp->seq->used; ++j) {
ret[count] = tmp->seq->elements[i]->uint;
++count;
}
ret[count] = '.';
++count;
}
ret[count-1] = '\x00';
return ret;
}
default:
return NULL;
}
assert(t != NULL);
assert(t->token_type == (HTokenType)TT_dns_domain);
return t->user;
}
uint8_t* get_cs(const HCountedArray *arr) {