2012-05-24 18:44:48 +02:00
|
|
|
#include "../src/hammer.h"
|
|
|
|
|
#include "dns_common.h"
|
|
|
|
|
|
|
|
|
|
#define false 0
|
|
|
|
|
#define true 1
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A label can't be more than 63 characters.
|
|
|
|
|
*/
|
2012-05-26 14:27:12 +02:00
|
|
|
bool validate_label(HParseResult *p) {
|
2012-05-24 18:44:48 +02:00
|
|
|
if (TT_SEQUENCE != p->ast->token_type)
|
|
|
|
|
return false;
|
|
|
|
|
return (64 > p->ast->seq->used);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-16 15:05:04 +01:00
|
|
|
|
2012-05-26 14:27:12 +02:00
|
|
|
const HParser* init_domain() {
|
|
|
|
|
static const HParser *domain = NULL;
|
2012-05-24 18:44:48 +02:00
|
|
|
if (domain)
|
|
|
|
|
return domain;
|
|
|
|
|
|
2012-05-26 14:27:12 +02:00
|
|
|
const HParser *letter = h_choice(h_ch_range('a', 'z'),
|
|
|
|
|
h_ch_range('A', 'Z'),
|
2012-05-24 18:44:48 +02:00
|
|
|
NULL);
|
|
|
|
|
|
2012-05-26 14:27:12 +02:00
|
|
|
const HParser *let_dig = h_choice(letter,
|
|
|
|
|
h_ch_range('0', '9'),
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
const HParser *ldh_str = h_many1(h_choice(let_dig,
|
|
|
|
|
h_ch('-'),
|
|
|
|
|
NULL));
|
2012-05-24 18:44:48 +02:00
|
|
|
|
2012-05-26 14:27:12 +02:00
|
|
|
const HParser *label = h_attr_bool(h_sequence(letter,
|
|
|
|
|
h_optional(h_sequence(h_optional(ldh_str),
|
|
|
|
|
let_dig,
|
|
|
|
|
NULL)),
|
|
|
|
|
NULL),
|
|
|
|
|
validate_label);
|
2012-05-24 18:44:48 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* You could write it like this ...
|
2012-05-26 14:27:12 +02:00
|
|
|
* HParser *indirect_subdomain = h_indirect();
|
|
|
|
|
* const HParser *subdomain = h_choice(label,
|
|
|
|
|
* h_sequence(indirect_subdomain,
|
|
|
|
|
* h_ch('.'),
|
|
|
|
|
* label,
|
|
|
|
|
* NULL),
|
|
|
|
|
* NULL);
|
|
|
|
|
* h_bind_indirect(indirect_subdomain, subdomain);
|
2012-05-24 18:44:48 +02:00
|
|
|
*
|
|
|
|
|
* ... but this is easier and equivalent
|
|
|
|
|
*/
|
|
|
|
|
|
2012-05-26 14:27:12 +02:00
|
|
|
const HParser *subdomain = h_sepBy1(label, h_ch('.'));
|
2012-05-24 18:44:48 +02:00
|
|
|
|
2012-05-26 14:27:12 +02:00
|
|
|
domain = h_choice(subdomain,
|
|
|
|
|
h_ch(' '),
|
|
|
|
|
NULL);
|
2012-05-24 18:44:48 +02:00
|
|
|
|
|
|
|
|
return domain;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-26 13:23:00 +02:00
|
|
|
const HParser* init_character_string() {
|
|
|
|
|
static const HParser *cstr = NULL;
|
2012-05-24 18:44:48 +02:00
|
|
|
if (cstr)
|
|
|
|
|
return cstr;
|
|
|
|
|
|
2012-05-26 14:27:12 +02:00
|
|
|
cstr = h_length_value(h_uint8(), h_uint8());
|
2012-05-24 18:44:48 +02:00
|
|
|
|
|
|
|
|
return cstr;
|
|
|
|
|
}
|