xref: /freebsd/sbin/ipf/libipf/printpool.c (revision abd87254)
1 
2 /*
3  * Copyright (C) 2012 by Darren Reed.
4  *
5  * See the IPFILTER.LICENCE file for details on licencing.
6  */
7 
8 #include "ipf.h"
9 
10 
11 ip_pool_t *
12 printpool(ip_pool_t *pp, copyfunc_t copyfunc, char *name, int opts,
13 	wordtab_t *fields)
14 {
15 	ip_pool_node_t *ipnp, *ipnpn, ipn, **pnext;
16 	ip_pool_t ipp;
17 
18 	if ((*copyfunc)(pp, &ipp, sizeof(ipp)))
19 		return (NULL);
20 
21 	if ((name != NULL) && strncmp(name, ipp.ipo_name, FR_GROUPLEN))
22 		return (ipp.ipo_next);
23 
24 	printpooldata(&ipp, opts);
25 
26 	if ((ipp.ipo_flags & IPOOL_DELETE) != 0)
27 		PRINTF("# ");
28 	if ((opts & OPT_DEBUG) == 0)
29 		PRINTF("\t{");
30 
31 	ipnpn = ipp.ipo_list;
32 	ipp.ipo_list = NULL;
33 	pnext = &ipp.ipo_list;
34 	while (ipnpn != NULL) {
35 		ipnp = (ip_pool_node_t *)malloc(sizeof(*ipnp));
36 		(*copyfunc)(ipnpn, ipnp, sizeof(ipn));
37 		ipnpn = ipnp->ipn_next;
38 		*pnext = ipnp;
39 		pnext = &ipnp->ipn_next;
40 		ipnp->ipn_next = NULL;
41 	}
42 
43 	if (ipp.ipo_list == NULL) {
44 		putchar(';');
45 	} else {
46 		for (ipnp = ipp.ipo_list; ipnp != NULL; ipnp = ipnpn) {
47 			ipnpn = printpoolnode(ipnp, opts, fields);
48 			free(ipnp);
49 
50 			if ((opts & OPT_DEBUG) == 0) {
51 				putchar(';');
52 			}
53 		}
54 	}
55 
56 	if ((opts & OPT_DEBUG) == 0)
57 		PRINTF(" };\n");
58 
59 	return (ipp.ipo_next);
60 }
61