Skip to content

Commit

Permalink
$GENERATE half-way done.
Browse files Browse the repository at this point in the history
  • Loading branch information
tobez committed Feb 1, 2016
1 parent 648da71 commit e0e8714
Show file tree
Hide file tree
Showing 28 changed files with 94 additions and 53 deletions.
2 changes: 1 addition & 1 deletion afsdb.c
Expand Up @@ -21,7 +21,7 @@ static struct rr *afsdb_parse(char *name, long ttl, int type, char *s)
{
struct rr_afsdb *rr = getmem(sizeof(*rr));

rr->subtype = extract_integer(&s, "AFSDB subtype");
rr->subtype = extract_integer(&s, "AFSDB subtype", NULL);
if (rr->subtype < 0)
return NULL;

Expand Down
6 changes: 3 additions & 3 deletions cert.c
Expand Up @@ -30,7 +30,7 @@ static int extract_certificate_type(char **s, char *what)
char *str_type;

if (isdigit(**s)) {
type = extract_integer(s, what);
type = extract_integer(s, what, NULL);
if (type >= 1 && type <= 8)
return type;
if (type == 253 || type == 254)
Expand Down Expand Up @@ -84,14 +84,14 @@ static struct rr* cert_parse(char *name, long ttl, int type, char *s)
if (cert_type < 0) return NULL;
rr->type = cert_type;

key_tag = extract_integer(&s, "key tag");
key_tag = extract_integer(&s, "key tag", NULL);
if (key_tag < 0) return NULL;
if (key_tag > 65535)
return bitch("bad key tag");
rr->key_tag = key_tag;

if (isdigit(*s)) {
alg = extract_integer(&s, "algorithm");
alg = extract_integer(&s, "algorithm", NULL);
if (alg < 0) return NULL;
if (alg > 255) return bitch("bad algorithm");
if (alg != 0) { /* 0 is just fine */
Expand Down
5 changes: 5 additions & 0 deletions common.h
Expand Up @@ -18,6 +18,11 @@ struct file_info
char buf[2048];
char *current_origin;
char name[0];

int generate_cur;
int generate_lim;
int generate_lhs;
int generate_rhs;
};

extern struct file_info *file_info;
Expand Down
4 changes: 2 additions & 2 deletions dlv.c
Expand Up @@ -22,15 +22,15 @@ static struct rr* dlv_parse(char *name, long ttl, int type, char *s)
struct rr_dlv *rr = getmem(sizeof(*rr));
int key_tag, algorithm, digest_type;

key_tag = extract_integer(&s, "key tag");
key_tag = extract_integer(&s, "key tag", NULL);
if (key_tag < 0) return NULL;
rr->key_tag = key_tag;

algorithm = extract_algorithm(&s, "algorithm");
if (algorithm == ALG_UNSUPPORTED) return NULL;
rr->algorithm = algorithm;

digest_type = extract_integer(&s, "digest type");
digest_type = extract_integer(&s, "digest type", NULL);
if (digest_type < 0) return NULL;
rr->digest_type = digest_type;

Expand Down
4 changes: 2 additions & 2 deletions dnskey.c
Expand Up @@ -31,7 +31,7 @@ static struct rr* dnskey_parse(char *name, long ttl, int type, char *s)
int i;
static struct rr *result;

flags = extract_integer(&s, "flags");
flags = extract_integer(&s, "flags", NULL);
if (flags < 0) return NULL;
if (flags & 0xfe7e)
return bitch("reserved flags bits are set");
Expand All @@ -41,7 +41,7 @@ static struct rr* dnskey_parse(char *name, long ttl, int type, char *s)

/* TODO validate that `name` is the name of the zone if flags have Zone Key bit set */

proto = extract_integer(&s, "protocol");
proto = extract_integer(&s, "protocol", NULL);
if (proto < 0) return NULL;
if (proto != 3)
return bitch("bad protocol value");
Expand Down
4 changes: 2 additions & 2 deletions ds.c
Expand Up @@ -22,15 +22,15 @@ static struct rr* ds_parse(char *name, long ttl, int type, char *s)
struct rr_ds *rr = getmem(sizeof(*rr));
int key_tag, algorithm, digest_type;

key_tag = extract_integer(&s, "key tag");
key_tag = extract_integer(&s, "key tag", NULL);
if (key_tag < 0) return NULL;
rr->key_tag = key_tag;

algorithm = extract_algorithm(&s, "algorithm");
if (algorithm == ALG_UNSUPPORTED) return NULL;
rr->algorithm = algorithm;

digest_type = extract_integer(&s, "digest type");
digest_type = extract_integer(&s, "digest type", NULL);
if (digest_type < 0) return NULL;
rr->digest_type = digest_type;

Expand Down
6 changes: 3 additions & 3 deletions ipseckey.c
Expand Up @@ -24,15 +24,15 @@ static struct rr *ipseckey_parse(char *name, long ttl, int type, char *s)
struct rr_ipseckey *rr = getmem(sizeof(*rr));
int i;

rr->precedence = i = extract_integer(&s, "precedence");
rr->precedence = i = extract_integer(&s, "precedence", NULL);
if (i < 0) return NULL;
if (i >= 256) return bitch("precedence range is not valid");

rr->gateway_type = i = extract_integer(&s, "gateway type");
rr->gateway_type = i = extract_integer(&s, "gateway type", NULL);
if (i < 0) return NULL;
if (i > 3) return bitch("gateway type is not valid");

rr->algorithm = i = extract_integer(&s, "algorithm");
rr->algorithm = i = extract_integer(&s, "algorithm", NULL);
if (i < 0) return NULL;
if (i > 2) return bitch("algorithm is not valid");

Expand Down
2 changes: 1 addition & 1 deletion kx.c
Expand Up @@ -21,7 +21,7 @@ static struct rr *kx_parse(char *name, long ttl, int type, char *s)
{
struct rr_kx *rr = getmem(sizeof(*rr));

rr->preference = extract_integer(&s, "KX preference");
rr->preference = extract_integer(&s, "KX preference", NULL);
if (rr->preference < 0)
return NULL;

Expand Down
2 changes: 1 addition & 1 deletion l32.c
Expand Up @@ -23,7 +23,7 @@ static struct rr *l32_parse(char *name, long ttl, int type, char *s)
struct in_addr ipv4_like;
int preference;

rr->preference = preference = extract_integer(&s, "L32 preference");
rr->preference = preference = extract_integer(&s, "L32 preference", NULL);
if (preference < 0)
return NULL;
if (extract_ipv4(&s, "Locator32", &ipv4_like) <= 0)
Expand Down
2 changes: 1 addition & 1 deletion l64.c
Expand Up @@ -22,7 +22,7 @@ static struct rr *l64_parse(char *name, long ttl, int type, char *s)
struct rr_l64 *rr = getmem(sizeof(*rr));
int preference;

rr->preference = preference = extract_integer(&s, "L64 preference");
rr->preference = preference = extract_integer(&s, "L64 preference", NULL);
if (preference < 0)
return NULL;
if (extract_u64(&s, "Locator64", &rr->locator64) < 0)
Expand Down
8 changes: 4 additions & 4 deletions loc.c
Expand Up @@ -56,7 +56,7 @@ static struct rr *loc_parse(char *name, long ttl, int type, char *s)
rr->version = 0;

/* latitude block */
i = extract_integer(&s, "degrees latitude");
i = extract_integer(&s, "degrees latitude", NULL);
if (i < 0)
return NULL;
if (i > 90)
Expand All @@ -65,7 +65,7 @@ static struct rr *loc_parse(char *name, long ttl, int type, char *s)
min = 0;
sec = 0;
if (isdigit(*s)) {
i = extract_integer(&s, "minutes latitude");
i = extract_integer(&s, "minutes latitude", NULL);
if (i < 0)
return NULL;
if (i > 59)
Expand Down Expand Up @@ -96,7 +96,7 @@ static struct rr *loc_parse(char *name, long ttl, int type, char *s)
if (!s) return NULL;

/* longitude block */
i = extract_integer(&s, "degrees longitude");
i = extract_integer(&s, "degrees longitude", NULL);
if (i < 0)
return NULL;
if (i > 180)
Expand All @@ -105,7 +105,7 @@ static struct rr *loc_parse(char *name, long ttl, int type, char *s)
min = 0;
sec = 0;
if (isdigit(*s)) {
i = extract_integer(&s, "minutes longitude");
i = extract_integer(&s, "minutes longitude", NULL);
if (i < 0)
return NULL;
if (i > 59)
Expand Down
2 changes: 1 addition & 1 deletion lp.c
Expand Up @@ -23,7 +23,7 @@ static struct rr *lp_parse(char *name, long ttl, int type, char *s)
struct rr_lp *rr = getmem(sizeof(*rr));
int preference;

rr->preference = preference = extract_integer(&s, "LP preference");
rr->preference = preference = extract_integer(&s, "LP preference", NULL);
if (preference < 0)
return NULL;
rr->fqdn = extract_name(&s, "LP fqdn", 0);
Expand Down
33 changes: 33 additions & 0 deletions main.c
Expand Up @@ -72,6 +72,39 @@ static char *process_directive(char *s)
fprintf(stderr, "-> %s:%d: ", file_info->name, file_info->line);
fprintf(stderr, "default ttl is now %ld\n", G.default_ttl);
}
} else if (*(s+1) == 'G' && strncmp(s, "$GENERATE", 9) == 0) {
int from, to;
char *lhs, *rhs;

s += 9;
if (!isspace(*s)) {
if (isalnum(*s)) goto unrecognized_directive;
return bitch("bad $GENERATE format");
}
s = skip_white_space(s);

from = extract_integer(&s, "generate-from", "-");
if (from < 0)
return NULL;
if (*s != '-')
return bitch("'-' between generate-from and generate-to is expected");
s++;
to = extract_integer(&s, "generate-to", "-");
if (to < 0)
return NULL;

if (*s == '/')
return bitch("generate-step is unsupported for now");

lhs = extract_name(&s, "generate-lhs", KEEP_CAPITALIZATION | DOLLAR_OK_IN_NAMES);
if (!lhs)
return NULL;

if (*s == '{')
return bitch("{offset,width,type} is unsupported for now");

rhs = quickstrdup(s);
return rhs;
} else if (*(s+1) == 'I' && strncmp(s, "$INCLUDE", 8) == 0) {
char *p, *f;
char c;
Expand Down
2 changes: 1 addition & 1 deletion mx.c
Expand Up @@ -21,7 +21,7 @@ static struct rr *mx_parse(char *name, long ttl, int type, char *s)
{
struct rr_mx *rr = getmem(sizeof(*rr));

rr->preference = extract_integer(&s, "MX preference");
rr->preference = extract_integer(&s, "MX preference", NULL);
if (rr->preference < 0)
return NULL;
/* XXX preference range check */
Expand Down
4 changes: 2 additions & 2 deletions naptr.c
Expand Up @@ -24,14 +24,14 @@ static struct rr *naptr_parse(char *name, long ttl, int type, char *s)
int i;
struct binary_data text;

i = extract_integer(&s, "order");
i = extract_integer(&s, "order", NULL);
if (i < 0)
return NULL;
if (i >= 65536)
return bitch("order range is not valid");
rr->order = i;

i = extract_integer(&s, "preference");
i = extract_integer(&s, "preference", NULL);
if (i < 0)
return NULL;
if (i >= 65536)
Expand Down
2 changes: 1 addition & 1 deletion nid.c
Expand Up @@ -22,7 +22,7 @@ static struct rr *nid_parse(char *name, long ttl, int type, char *s)
struct rr_nid *rr = getmem(sizeof(*rr));
int preference;

rr->preference = preference = extract_integer(&s, "NID preference");
rr->preference = preference = extract_integer(&s, "NID preference", NULL);
if (preference < 0)
return NULL;
if (extract_u64(&s, "NodeID", &rr->node_id) < 0)
Expand Down
6 changes: 3 additions & 3 deletions nsec3.c
Expand Up @@ -31,7 +31,7 @@ static struct rr* nsec3_parse(char *name, long ttl, int type, char *s)
char *str_type = NULL;
int ltype;

i = extract_integer(&s, "hash algorithm");
i = extract_integer(&s, "hash algorithm", NULL);
if (i < 0)
return NULL;
if (i > 255)
Expand All @@ -40,7 +40,7 @@ static struct rr* nsec3_parse(char *name, long ttl, int type, char *s)
return bitch("unrecognized or unsupported hash algorithm");
rr->hash_algorithm = i;

i = extract_integer(&s, "flags");
i = extract_integer(&s, "flags", NULL);
if (i < 0)
return NULL;
if (i > 255)
Expand All @@ -52,7 +52,7 @@ static struct rr* nsec3_parse(char *name, long ttl, int type, char *s)
opt_out = 1;
rr->flags = i;

i = extract_integer(&s, "iterations");
i = extract_integer(&s, "iterations", NULL);
if (i < 0)
return NULL;
if (i > 2500)
Expand Down
6 changes: 3 additions & 3 deletions nsec3param.c
Expand Up @@ -27,7 +27,7 @@ static struct rr* nsec3param_parse(char *name, long ttl, int type, char *s)
struct rr *ret_rr;
int i;

i = extract_integer(&s, "hash algorithm");
i = extract_integer(&s, "hash algorithm", NULL);
if (i < 0)
return NULL;
if (i > 255)
Expand All @@ -36,7 +36,7 @@ static struct rr* nsec3param_parse(char *name, long ttl, int type, char *s)
return bitch("unrecognized or unsupported hash algorithm");
rr->hash_algorithm = i;

i = extract_integer(&s, "flags");
i = extract_integer(&s, "flags", NULL);
if (i < 0)
return NULL;
if (i > 255)
Expand All @@ -45,7 +45,7 @@ static struct rr* nsec3param_parse(char *name, long ttl, int type, char *s)
return bitch("flags is supposed to be 0 for NSEC3PARAM");
rr->flags = i;

i = extract_integer(&s, "iterations");
i = extract_integer(&s, "iterations", NULL);
if (i < 0)
return NULL;
if (i > 2500)
Expand Down
2 changes: 1 addition & 1 deletion px.c
Expand Up @@ -21,7 +21,7 @@ static struct rr *px_parse(char *name, long ttl, int type, char *s)
{
struct rr_px *rr = getmem(sizeof(*rr));

rr->preference = extract_integer(&s, "PX preference");
rr->preference = extract_integer(&s, "PX preference", NULL);
if (rr->preference < 0)
return NULL;

Expand Down
4 changes: 2 additions & 2 deletions rr.c
Expand Up @@ -432,7 +432,7 @@ struct rr *rr_parse_any(char *name, long ttl, int type, char *s)
s = skip_white_space(s);
if (!s) return NULL;

len = extract_integer(&s, "custom data size");
len = extract_integer(&s, "custom data size", NULL);
if (len < 0) return NULL;
if (len > 65535) goto invalid;

Expand Down Expand Up @@ -810,7 +810,7 @@ int extract_algorithm(char **s, char *what)
char *str_alg;

if (isdigit(**s)) {
alg = extract_integer(s, what);
alg = extract_integer(s, what, NULL);
if (algorithm_type(alg) == ALG_UNSUPPORTED) {
bitch("bad or unsupported algorithm %d", alg);
return ALG_UNSUPPORTED;
Expand Down
4 changes: 2 additions & 2 deletions rrsig.c
Expand Up @@ -64,7 +64,7 @@ static struct rr* rrsig_parse(char *name, long ttl, int type, char *s)
return bitch("private algorithms are not supported in RRSIG");
}

rr->labels = extract_integer(&s, "labels");
rr->labels = extract_integer(&s, "labels", NULL);
if (rr->labels < 0) return NULL;
/* TODO validate labels, see http://tools.ietf.org/html/rfc4034#section-3.1.3 */

Expand All @@ -79,7 +79,7 @@ static struct rr* rrsig_parse(char *name, long ttl, int type, char *s)
if (ts < 0) return NULL;
rr->sig_inception = ts;

key_tag = extract_integer(&s, "key tag");
key_tag = extract_integer(&s, "key tag", NULL);
if (key_tag < 0) return NULL;
rr->key_tag = key_tag;

Expand Down
2 changes: 1 addition & 1 deletion rt.c
Expand Up @@ -21,7 +21,7 @@ static struct rr *rt_parse(char *name, long ttl, int type, char *s)
{
struct rr_rt *rr = getmem(sizeof(*rr));

rr->preference = extract_integer(&s, "RT preference");
rr->preference = extract_integer(&s, "RT preference", NULL);
if (rr->preference < 0)
return NULL;

Expand Down
2 changes: 1 addition & 1 deletion soa.c
Expand Up @@ -27,7 +27,7 @@ static struct rr* soa_parse(char *name, long ttl, int type, char *s)
if (!rr->mname) return NULL;
rr->rname = extract_name(&s, "rname", 0);
if (!rr->rname) return NULL;
i = extract_integer(&s, "serial");
i = extract_integer(&s, "serial", NULL);
if (i < 0) return NULL;
if (i > 4294967295UL) return bitch("serial is out of range");
rr->serial = i;
Expand Down

0 comments on commit e0e8714

Please sign in to comment.