Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / bind / irs / lcl.c
blobe14ed5224719db5176a0d8ddf9b0f1a4ed0555c6
1 /*
2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (c) 1996-1999 by Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #if !defined(LINT) && !defined(CODECENTER)
19 static const char rcsid[] = "$Id: lcl.c,v 1.1.2.2 2004/03/17 00:40:13 marka Exp $";
20 #endif
22 /* Imports */
24 #include "port_before.h"
26 #include <stdlib.h>
27 #include <errno.h>
28 #include <string.h>
30 #include <sys/types.h>
31 #include <netinet/in.h>
32 #include <arpa/nameser.h>
33 #include <resolv.h>
35 #include <isc/memcluster.h>
37 #include <irs.h>
39 #include "port_after.h"
41 #include "irs_p.h"
42 #include "lcl_p.h"
44 /* Forward. */
46 static void lcl_close(struct irs_acc *);
47 static struct __res_state * lcl_res_get(struct irs_acc *);
48 static void lcl_res_set(struct irs_acc *, struct __res_state *,
49 void (*)(void *));
51 /* Public */
53 struct irs_acc *
54 irs_lcl_acc(const char *options) {
55 struct irs_acc *acc;
56 struct lcl_p *lcl;
58 UNUSED(options);
60 if (!(acc = memget(sizeof *acc))) {
61 errno = ENOMEM;
62 return (NULL);
64 memset(acc, 0x5e, sizeof *acc);
65 if (!(lcl = memget(sizeof *lcl))) {
66 errno = ENOMEM;
67 free(acc);
68 return (NULL);
70 memset(lcl, 0x5e, sizeof *lcl);
71 lcl->res = NULL;
72 lcl->free_res = NULL;
73 acc->private = lcl;
74 #ifdef WANT_IRS_GR
75 acc->gr_map = irs_lcl_gr;
76 #else
77 acc->gr_map = NULL;
78 #endif
79 #ifdef WANT_IRS_PW
80 acc->pw_map = irs_lcl_pw;
81 #else
82 acc->pw_map = NULL;
83 #endif
84 acc->sv_map = irs_lcl_sv;
85 acc->pr_map = irs_lcl_pr;
86 acc->ho_map = irs_lcl_ho;
87 acc->nw_map = irs_lcl_nw;
88 acc->ng_map = irs_lcl_ng;
89 acc->res_get = lcl_res_get;
90 acc->res_set = lcl_res_set;
91 acc->close = lcl_close;
92 return (acc);
95 /* Methods */
96 static struct __res_state *
97 lcl_res_get(struct irs_acc *this) {
98 struct lcl_p *lcl = (struct lcl_p *)this->private;
100 if (lcl->res == NULL) {
101 struct __res_state *res;
102 res = (struct __res_state *)malloc(sizeof *res);
103 if (res == NULL)
104 return (NULL);
105 memset(res, 0, sizeof *res);
106 lcl_res_set(this, res, free);
109 if ((lcl->res->options & RES_INIT) == 0U &&
110 res_ninit(lcl->res) < 0)
111 return (NULL);
113 return (lcl->res);
116 static void
117 lcl_res_set(struct irs_acc *this, struct __res_state *res,
118 void (*free_res)(void *)) {
119 struct lcl_p *lcl = (struct lcl_p *)this->private;
121 if (lcl->res && lcl->free_res) {
122 res_nclose(lcl->res);
123 (*lcl->free_res)(lcl->res);
126 lcl->res = res;
127 lcl->free_res = free_res;
130 static void
131 lcl_close(struct irs_acc *this) {
132 struct lcl_p *lcl = (struct lcl_p *)this->private;
134 if (lcl) {
135 if (lcl->free_res)
136 (*lcl->free_res)(lcl->res);
137 memput(lcl, sizeof *lcl);
139 memput(this, sizeof *this);