4 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (c) 1996,1999 by Internet Software Consortium.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #if !defined(LINT) && !defined(CODECENTER)
21 static const char rcsid
[] = "Id: gen_ng.c,v 1.3 2005/04/27 04:56:23 sra Exp";
26 #include "port_before.h"
28 #include <sys/types.h>
30 #include <netinet/in.h>
31 #include <arpa/nameser.h>
38 #include <isc/memcluster.h>
41 #include "port_after.h"
49 struct irs_rule
* rules
;
50 struct irs_rule
* rule
;
56 static void ng_close(struct irs_ng
*);
57 static int ng_next(struct irs_ng
*, const char **,
58 const char **, const char **);
59 static int ng_test(struct irs_ng
*, const char *,
60 const char *, const char *,
62 static void ng_rewind(struct irs_ng
*, const char *);
63 static void ng_minimize(struct irs_ng
*);
68 irs_gen_ng(struct irs_acc
*this) {
69 struct gen_p
*accpvt
= (struct gen_p
*)this->private;
73 if (!(ng
= memget(sizeof *ng
))) {
77 memset(ng
, 0x5e, sizeof *ng
);
78 if (!(pvt
= memget(sizeof *pvt
))) {
79 memput(ng
, sizeof *ng
);
83 memset(pvt
, 0, sizeof *pvt
);
84 pvt
->rules
= accpvt
->map_rules
[irs_ng
];
85 pvt
->rule
= pvt
->rules
;
90 ng
->rewind
= ng_rewind
;
91 ng
->minimize
= ng_minimize
;
98 ng_close(struct irs_ng
*this) {
99 struct pvt
*pvt
= (struct pvt
*)this->private;
104 memput(pvt
, sizeof *pvt
);
105 memput(this, sizeof *this);
109 ng_next(struct irs_ng
*this, const char **host
, const char **user
,
112 struct pvt
*pvt
= (struct pvt
*)this->private;
116 ng
= pvt
->rule
->inst
->ng
;
117 if ((*ng
->next
)(ng
, host
, user
, domain
) == 1)
119 if (!(pvt
->rule
->flags
& IRS_CONTINUE
))
121 pvt
->rule
= pvt
->rule
->next
;
123 ng
= pvt
->rule
->inst
->ng
;
124 (*ng
->rewind
)(ng
, pvt
->curgroup
);
131 ng_test(struct irs_ng
*this, const char *name
,
132 const char *user
, const char *host
, const char *domain
)
134 struct pvt
*pvt
= (struct pvt
*)this->private;
135 struct irs_rule
*rule
;
140 for (rule
= pvt
->rules
; rule
; rule
= rule
->next
) {
142 rval
= (*ng
->test
)(ng
, name
, user
, host
, domain
);
143 if (rval
|| !(rule
->flags
& IRS_CONTINUE
))
150 ng_rewind(struct irs_ng
*this, const char *group
) {
151 struct pvt
*pvt
= (struct pvt
*)this->private;
154 pvt
->rule
= pvt
->rules
;
158 pvt
->curgroup
= strdup(group
);
159 ng
= pvt
->rule
->inst
->ng
;
160 (*ng
->rewind
)(ng
, pvt
->curgroup
);
165 ng_minimize(struct irs_ng
*this) {
166 struct pvt
*pvt
= (struct pvt
*)this->private;
167 struct irs_rule
*rule
;
169 for (rule
= pvt
->rules
; rule
!= NULL
; rule
= rule
->next
) {
170 struct irs_ng
*ng
= rule
->inst
->ng
;