
#include "ip4addr.h"

void log(int level, const char *fmt, ...);
void zlog(int level, int lineno, const char *fmt, ...);
void zloaded(const char *fmt, ...);

struct zonedata;
struct dnspacket;

#define R_A_DEFAULT ((ip4addr_t)0x7f000002)

typedef struct zonedata *z_loadfn(FILE *f);
typedef void z_freefn(struct zonedata *zone);
typedef int
z_queryfn(const struct zonedata *const zone, struct dnspacket *p,
          const unsigned char *const query, unsigned qflg);

#define QUERY_A   0x01
#define QUERY_NS  0x02
#define QUERY_SOA 0x04
#define QUERY_TXT 0x08

int
readzlines(FILE *f, struct zonedata *z,
           int (*zlpfn)(struct zonedata *z,
                        char *line, int lineno, int llines));

/* see details of DNS packet structure in rbldnsd.c */

int addrec_a(struct dnspacket *p, ip4addr_t aip);
int addrec_txt(struct dnspacket *p, const char *txt, const char *subst);

ip4addr_t dntoip4addr(const unsigned char *q);

/* list of zone types */
#define definezonetype(t) \
  z_queryfn t##_query; z_loadfn t##_load; z_freefn t##_free
#define dnset_descr "set of domain names"
definezonetype(dnset);
#define dnvset_descr "set of (domain name, value) pairs"
definezonetype(dnvset);
#define ip4set_descr "set of ip4 addresses with the same result"
definezonetype(ip4set);
#define ip4vset_descr "set of (ip4, value) pairs"
definezonetype(ip4vset);
#define generic_descr "generic DNS records (simplified BIND format)"
definezonetype(generic);
#undef definezonetype

int addrtxt(char *str, ip4addr_t *ap, char **txtp);

void oom();
void *emalloc(unsigned size);
void *erealloc(void *ptr, unsigned size);
char *estrdup(const char *str);
struct mempool;
void *mp_ealloc(struct mempool *mp, unsigned size);
char *mp_estrdup(struct mempool *mp, const char *str);
struct strpool;
const char *sp_estrdup(struct strpool *sp, const char *str);
