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: gen_ng.c,v 1.1.2.1 2004/03/09 09:17:29 marka Exp $";
24 #include "port_before.h"
26 #include <sys/types.h>
28 #include <netinet/in.h>
29 #include <arpa/nameser.h>
36 #include <isc/memcluster.h>
39 #include "port_after.h"
47 struct irs_rule
* rules
;
48 struct irs_rule
* rule
;
54 static void ng_close(struct irs_ng
*);
55 static int ng_next(struct irs_ng
*, const char **,
56 const char **, const char **);
57 static int ng_test(struct irs_ng
*, const char *,
58 const char *, const char *,
60 static void ng_rewind(struct irs_ng
*, const char *);
61 static void ng_minimize(struct irs_ng
*);
66 irs_gen_ng(struct irs_acc
*this) {
67 struct gen_p
*accpvt
= (struct gen_p
*)this->private;
71 if (!(ng
= memget(sizeof *ng
))) {
75 memset(ng
, 0x5e, sizeof *ng
);
76 if (!(pvt
= memget(sizeof *pvt
))) {
77 memput(ng
, sizeof *ng
);
81 memset(pvt
, 0, sizeof *pvt
);
82 pvt
->rules
= accpvt
->map_rules
[irs_ng
];
83 pvt
->rule
= pvt
->rules
;
88 ng
->rewind
= ng_rewind
;
89 ng
->minimize
= ng_minimize
;
96 ng_close(struct irs_ng
*this) {
97 struct pvt
*pvt
= (struct pvt
*)this->private;
102 memput(pvt
, sizeof *pvt
);
103 memput(this, sizeof *this);
107 ng_next(struct irs_ng
*this, const char **host
, const char **user
,
110 struct pvt
*pvt
= (struct pvt
*)this->private;
114 ng
= pvt
->rule
->inst
->ng
;
115 if ((*ng
->next
)(ng
, host
, user
, domain
) == 1)
117 if (!(pvt
->rule
->flags
& IRS_CONTINUE
))
119 pvt
->rule
= pvt
->rule
->next
;
121 ng
= pvt
->rule
->inst
->ng
;
122 (*ng
->rewind
)(ng
, pvt
->curgroup
);
129 ng_test(struct irs_ng
*this, const char *name
,
130 const char *user
, const char *host
, const char *domain
)
132 struct pvt
*pvt
= (struct pvt
*)this->private;
133 struct irs_rule
*rule
;
138 for (rule
= pvt
->rules
; rule
; rule
= rule
->next
) {
140 rval
= (*ng
->test
)(ng
, name
, user
, host
, domain
);
141 if (rval
|| !(rule
->flags
& IRS_CONTINUE
))
148 ng_rewind(struct irs_ng
*this, const char *group
) {
149 struct pvt
*pvt
= (struct pvt
*)this->private;
152 pvt
->rule
= pvt
->rules
;
156 pvt
->curgroup
= strdup(group
);
157 ng
= pvt
->rule
->inst
->ng
;
158 (*ng
->rewind
)(ng
, pvt
->curgroup
);
163 ng_minimize(struct irs_ng
*this) {
164 struct pvt
*pvt
= (struct pvt
*)this->private;
165 struct irs_rule
*rule
;
167 for (rule
= pvt
->rules
; rule
!= NULL
; rule
= rule
->next
) {
168 struct irs_ng
*ng
= rule
->inst
->ng
;