Commit 3a4bfc49 authored by James Brister's avatar James Brister
Browse files

Added some more meat to the zone structures.

parent 709f92bb
......@@ -18,6 +18,7 @@
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <dns/types.h>
......@@ -27,14 +28,8 @@
#include "zone.h"
/*
NOTES
- This needs to be fixed for threads.
-
- we do not 'realloc' to keep all the zones in contiguous memory.
* NOTE: we do not 'realloc' to keep all the zones in contiguous memory.
*
*/
#define ZONECHUNK 50 /* how many zone structs we make at once.*/
......@@ -42,11 +37,6 @@
#define ZONE_FREE_MAGIC 0x0
static isc_result_t set_string(char **string, size_t *len,
const char *source, isc_mem_t *mem);
isc_result_t
isc_zone_newcontext(isc_mem_t *memctx, isc_zonectx_t **zctx)
{
......@@ -70,11 +60,15 @@ isc_zone_newcontext(isc_mem_t *memctx, isc_zonectx_t **zctx)
isc_result_t
isc_zone_freecontext(isc_zonectx_t *zonectx)
{
isc_zoneinfo_t *zi ;
isc_zoneinfo_t *zi;
isc_zoneinfo_t *zp;
zi = ISC_LIST_HEAD(zonectx->freezones) ;
zi = ISC_LIST_HEAD(zonectx->freezones);
while (zi != NULL ) {
isc_zone_release_zone(zi);
zp = zi;
zi = ISC_LIST_NEXT(zi, chainlink);
isc_zone_release_zone(zp);
}
return (ISC_R_SUCCESS);
......@@ -146,53 +140,153 @@ isc_zone_release_zone(isc_zoneinfo_t *zone)
isc_result_t
isc_zone_setsource(isc_zoneinfo_t *zone, const char *source)
{
size_t len;
INSIST(zone != NULL);
INSIST(source != NULL);
INSIST(strlen(source) > 0);
return (set_string(&zone->source, &zone->sourcelen,
source, zone->zctx->memctx));
len = strlen(source) + 1;
INSIST(len > 1);
zone->source.base = isc_mem_get(zone->zctx->memctx, len);
if (zone->source.base == NULL) {
return (ISC_R_NOMEMORY);
}
zone->source.length = len;
strcpy(zone->source.base, source);
return (ISC_R_SUCCESS);
}
isc_result_t
isc_zone_setorigin(isc_zoneinfo_t *zone, const char *source)
isc_zone_setorigin(isc_zoneinfo_t *zone, const char *origin)
{
size_t len;
INSIST(zone != NULL);
INSIST(source != NULL);
INSIST(strlen(source) > 0);
INSIST(origin != NULL);
return (set_string(&zone->origin, &zone->originlen,
source, zone->zctx->memctx));
}
len = strlen(origin) + 1;
INSIST(len > 1);
zone->origin.base = isc_mem_get(zone->zctx->memctx, len);
if (zone->origin.base == NULL) {
return (ISC_R_NOMEMORY);
}
zone->origin.length = len;
strcpy(zone->origin.base, origin);
return (ISC_R_SUCCESS);
}
static isc_result_t
set_string(char **string, size_t *len, const char *source, isc_mem_t *mem)
const char *
isc_zonetype_to_string(isc_zonet_t zone_type)
{
INSIST(string != NULL);
INSIST(len != 0);
INSIST(mem != NULL);
if (*len > 0 && *len <= strlen(source)) {
isc_mem_put(mem, *string, *len);
*len = 0;
*string = NULL;
const char *res = NULL;
switch (zone_type) {
case zone_master:
res = "master";
break;
case zone_slave:
res = "slave";
break;
case zone_hint:
res = "hint";
break;
case zone_stub:
res = "stub";
break;
case zone_forward:
res = "forward";
break;
}
if (*len == 0) {
size_t need = strlen(source) + 1;
INSIST (res != NULL);
*string = isc_mem_get(mem, need);
if (*string == NULL) {
return (ISC_R_NOMEMORY);
}
return (res);
}
void
isc_zonectx_dump(FILE *fp, isc_zonectx_t *ctx)
{
isc_zoneinfo_t *zi;
INSIST(ctx != NULL);
zi = ISC_LIST_HEAD(ctx->usedzones);
while (zi != NULL ) {
isc_zone_dump(fp, zi);
zi = ISC_LIST_NEXT(zi, chainlink);
}
}
strcpy (*string, source);
void
isc_zone_dump(FILE *fp, isc_zoneinfo_t *zone)
{
INSIST(fp != NULL);
INSIST(zone != NULL);
fprintf(fp, "zone \"%s\" %s {\n", zone->origin.base,
rrclass_to_string(zone->zone_class));
fprintf(fp, "\ttype %s;\n",isc_zonetype_to_string(zone->type));
/* XXX this will get more complicated */
fprintf(fp, "\tfile \"%s\";\n",zone->source.base);
fprintf(fp, "}\n");
}
isc_result_t
isc_zone_setclass(isc_zoneinfo_t *zone, isc_rrclass_t rrclass)
{
INSIST(zone != NULL);
zone->zone_class = rrclass;
return (ISC_R_SUCCESS);
}
const char *
rrclass_to_string(isc_rrclass_t rrclass)
{
const char *res;
switch (rrclass) {
case class_none:
res = "NONE";
break;
case class_any:
res = "ANY";
break;
case class_in:
res = "IN";
break;
case class_chaos:
res = "CHAOS";
break;
case class_hesiod:
res = "HESIOD";
break;
case class_hs:
res = "HS";
break;
default:
res = NULL;
break;
}
INSIST(res != NULL);
return (res);
}
......@@ -42,18 +42,22 @@ typedef enum {
} isc_zonet_t ;
typedef enum {
class_any, class_none, class_in, class_chaos, class_hesiod,
class_hs
} isc_rrclass_t;
/* This structure contains all the run-time information about a zone. */
struct isc_zoneinfo
{
isc_int32_t magic; /* private magic stamp for valid'ng */
size_t originlen;
char *origin; /* name of zone */
size_t sourcelen;
char *source; /* where zone data came from */
isc_textregion_t origin;
isc_textregion_t source;
isc_zonet_t type; /* master, slave etc. */
isc_rrclass_t zone_class; /* IN, CHAOS etc. */
dns_db_t *thedb;
......@@ -100,14 +104,31 @@ isc_result_t isc_zone_newinfo(isc_zonectx_t *zctx, isc_zoneinfo_t **zone);
isc_result_t isc_zone_release_zone(isc_zoneinfo_t *zone);
/* write named.conf-type format */
void isc_zone_dump(FILE *fp, isc_zoneinfo_t *zone);
/* Free up a zone and all associated data structures. The zone knows which
*zone context to go back to
*/
isc_result_t isc_zone_freezone(isc_zoneinfo_t *zone);
isc_result_t isc_zone_freecontext(isc_zonectx_t *ctx);
isc_result_t isc_zone_setsource(isc_zoneinfo_t *zone, const char *source);
isc_result_t isc_zone_setorigin(isc_zoneinfo_t *zone, const char *origin);
/* These functions copy the data they're given. */
isc_result_t isc_zone_setsource(isc_zoneinfo_t *zone,
const char *source);
isc_result_t isc_zone_setorigin(isc_zoneinfo_t *zone,
const char *origin);
isc_result_t isc_zone_setclass(isc_zoneinfo_t *zone, isc_rrclass_t class);
const char * isc_zonetype_to_string(isc_zonet_t zont_type);
void isc_zonectx_dump(FILE *fp, isc_zonectx_t *ctx);
void isc_zone_dump(FILE *fp, isc_zoneinfo_t *zone);
const char * rrclass_to_string(isc_rrclass_t rrclass);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment