]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bind/lib/irs/gen_nw.c
This commit was generated by cvs2svn to compensate for changes in r52894,
[FreeBSD/FreeBSD.git] / contrib / bind / lib / irs / gen_nw.c
1 /*
2  * Copyright (c) 1996 by Internet Software Consortium.
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
9  * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
10  * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
11  * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
13  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
14  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15  * SOFTWARE.
16  */
17
18 #if !defined(LINT) && !defined(CODECENTER)
19 static char rcsid[] = "$Id: gen_nw.c,v 1.8 1997/12/04 04:57:50 halley Exp $";
20 #endif
21
22 /* Imports */
23
24 #include "port_before.h"
25
26 #include <sys/types.h>
27
28 #include <errno.h>
29 #include <stdlib.h>
30 #include <string.h>
31
32 #include <irs.h>
33
34 #include "port_after.h"
35
36 #include "irs_p.h"
37 #include "gen_p.h"
38
39 /* Types */
40
41 struct pvt {
42         struct irs_rule *       rules;
43         struct irs_rule *       rule;
44 };
45
46 /* Forward */
47
48 static void             nw_close(struct irs_nw*);
49 static struct nwent *   nw_next(struct irs_nw *);
50 static struct nwent *   nw_byname(struct irs_nw *, const char *, int);
51 static struct nwent *   nw_byaddr(struct irs_nw *, void *, int, int);
52 static void             nw_rewind(struct irs_nw *);
53 static void             nw_minimize(struct irs_nw *);
54
55 /* Public */
56
57 struct irs_nw *
58 irs_gen_nw(struct irs_acc *this) {
59         struct gen_p *accpvt = (struct gen_p *)this->private;
60         struct irs_nw *nw;
61         struct pvt *pvt;
62
63         if (!(nw = (struct irs_nw *)malloc(sizeof *nw))) {
64                 errno = ENOMEM;
65                 return (NULL);
66         }
67         memset(nw, 0x5e, sizeof *nw);
68         if (!(pvt = (struct pvt *)malloc(sizeof *pvt))) {
69                 free(nw);
70                 errno = ENOMEM;
71                 return (NULL);
72         }
73         memset(pvt, 0, sizeof *pvt);
74         pvt->rules = accpvt->map_rules[irs_nw];
75         pvt->rule = pvt->rules;
76         nw->private = pvt;
77         nw->close = nw_close;
78         nw->next = nw_next;
79         nw->byname = nw_byname;
80         nw->byaddr = nw_byaddr;
81         nw->rewind = nw_rewind;
82         nw->minimize = nw_minimize;
83         return (nw);
84 }
85
86 /* Methods */
87
88 static void
89 nw_close(struct irs_nw *this) {
90         struct pvt *pvt = (struct pvt *)this->private;
91
92         free(pvt);
93         free(this);
94 }
95
96 static struct nwent *
97 nw_next(struct irs_nw *this) {
98         struct pvt *pvt = (struct pvt *)this->private;
99         struct nwent *rval;
100         struct irs_nw *nw;
101
102         while (pvt->rule) {
103                 nw = pvt->rule->inst->nw;
104                 rval = (*nw->next)(nw);
105                 if (rval)
106                         return (rval);
107                 if (!(pvt->rules->flags & IRS_CONTINUE))
108                         break;
109                 pvt->rule = pvt->rule->next;
110                 if (pvt->rule) {
111                         nw = pvt->rule->inst->nw;
112                         (*nw->rewind)(nw);
113                 }
114         }
115         return (NULL);
116 }
117
118 static struct nwent *
119 nw_byname(struct irs_nw *this, const char *name, int type) {
120         struct pvt *pvt = (struct pvt *)this->private;
121         struct irs_rule *rule;
122         struct nwent *rval;
123         struct irs_nw *nw;
124         
125         for (rule = pvt->rules; rule; rule = rule->next) {
126                 nw = rule->inst->nw;
127                 h_errno = NETDB_INTERNAL;
128                 rval = (*nw->byname)(nw, name, type);
129                 if (rval != NULL)
130                         return (rval);
131                 if (h_errno != TRY_AGAIN && !(rule->flags & IRS_CONTINUE))
132                         break;
133         }
134         return (NULL);
135 }
136
137 static struct nwent *
138 nw_byaddr(struct irs_nw *this, void *net, int length, int type) {
139         struct pvt *pvt = (struct pvt *)this->private;
140         struct irs_rule *rule;
141         struct nwent *rval;
142         struct irs_nw *nw;
143         
144         for (rule = pvt->rules; rule; rule = rule->next) {
145                 nw = rule->inst->nw;
146                 h_errno = NETDB_INTERNAL;
147                 rval = (*nw->byaddr)(nw, net, length, type);
148                 if (rval != NULL)
149                         return (rval);
150                 if (h_errno != TRY_AGAIN && !(rule->flags & IRS_CONTINUE))
151                         break;
152         }
153         return (NULL);
154 }
155
156 static void
157 nw_rewind(struct irs_nw *this) {
158         struct pvt *pvt = (struct pvt *)this->private;
159         struct irs_nw *nw;
160
161         pvt->rule = pvt->rules;
162         if (pvt->rule) {
163                 nw = pvt->rule->inst->nw;
164                 (*nw->rewind)(nw);
165         }
166 }
167
168 static void
169 nw_minimize(struct irs_nw *this) {
170         struct pvt *pvt = (struct pvt *)this->private;
171         struct irs_rule *rule;
172
173         for (rule = pvt->rules; rule != NULL; rule = rule->next) {
174                 struct irs_nw *nw = rule->inst->nw;
175
176                 (*nw->minimize)(nw);
177         }
178 }