diff options
Diffstat (limited to 'contrib/bind/lib/irs/gen_pr.c')
-rw-r--r-- | contrib/bind/lib/irs/gen_pr.c | 66 |
1 files changed, 59 insertions, 7 deletions
diff --git a/contrib/bind/lib/irs/gen_pr.c b/contrib/bind/lib/irs/gen_pr.c index 096be513c898..de0957165bf7 100644 --- a/contrib/bind/lib/irs/gen_pr.c +++ b/contrib/bind/lib/irs/gen_pr.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996 by Internet Software Consortium. + * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static char rcsid[] = "$Id: gen_pr.c,v 1.8 1997/12/04 04:57:51 halley Exp $"; +static const char rcsid[] = "$Id: gen_pr.c,v 1.12 1999/10/13 16:39:30 vixie Exp $"; #endif /* Imports */ @@ -24,11 +24,15 @@ static char rcsid[] = "$Id: gen_pr.c,v 1.8 1997/12/04 04:57:51 halley Exp $"; #include "port_before.h" #include <sys/types.h> +#include <netinet/in.h> +#include <arpa/nameser.h> #include <errno.h> +#include <resolv.h> #include <stdlib.h> #include <string.h> +#include <isc/memcluster.h> #include <irs.h> #include "port_after.h" @@ -41,6 +45,8 @@ static char rcsid[] = "$Id: gen_pr.c,v 1.8 1997/12/04 04:57:51 halley Exp $"; struct pvt { struct irs_rule * rules; struct irs_rule * rule; + struct __res_state * res; + void (*free_res)(void *); }; /* Forward */ @@ -51,6 +57,10 @@ static struct protoent * pr_byname(struct irs_pr *, const char *); static struct protoent * pr_bynumber(struct irs_pr *, int); static void pr_rewind(struct irs_pr *); static void pr_minimize(struct irs_pr *); +static struct __res_state * pr_res_get(struct irs_pr *); +static void pr_res_set(struct irs_pr *, + struct __res_state *, + void (*)(void *)); /* Public */ @@ -60,13 +70,13 @@ irs_gen_pr(struct irs_acc *this) { struct irs_pr *pr; struct pvt *pvt; - if (!(pr = (struct irs_pr *)malloc(sizeof *pr))) { + if (!(pr = memget(sizeof *pr))) { errno = ENOMEM; return (NULL); } memset(pr, 0x5e, sizeof *pr); - if (!(pvt = (struct pvt *)malloc(sizeof *pvt))) { - free(pr); + if (!(pvt = memget(sizeof *pvt))) { + memput(pr, sizeof *pr); errno = ENOMEM; return (NULL); } @@ -80,6 +90,8 @@ irs_gen_pr(struct irs_acc *this) { pr->bynumber = pr_bynumber; pr->rewind = pr_rewind; pr->minimize = pr_minimize; + pr->res_get = pr_res_get; + pr->res_set = pr_res_set; return (pr); } @@ -89,8 +101,8 @@ static void pr_close(struct irs_pr *this) { struct pvt *pvt = (struct pvt *)this->private; - free(pvt); - free(this); + memput(pvt, sizeof *pvt); + memput(this, sizeof *this); } static struct protoent * @@ -172,3 +184,43 @@ pr_minimize(struct irs_pr *this) { (*pr->minimize)(pr); } } + +static struct __res_state * +pr_res_get(struct irs_pr *this) { + struct pvt *pvt = (struct pvt *)this->private; + + if (!pvt->res) { + struct __res_state *res; + res = (struct __res_state *)malloc(sizeof *res); + if (!res) { + errno = ENOMEM; + return (NULL); + } + memset(res, 0, sizeof *res); + pr_res_set(this, res, free); + } + + return (pvt->res); +} + +static void +pr_res_set(struct irs_pr *this, struct __res_state *res, + void (*free_res)(void *)) { + struct pvt *pvt = (struct pvt *)this->private; + struct irs_rule *rule; + + if (pvt->res && pvt->free_res) { + res_nclose(pvt->res); + (*pvt->free_res)(pvt->res); + } + + pvt->res = res; + pvt->free_res = free_res; + + for (rule = pvt->rules; rule != NULL; rule = rule->next) { + struct irs_pr *pr = rule->inst->pr; + + if (pr->res_set) + (*pr->res_set)(pr, pvt->res, NULL); + } +} |