flose files & free memory when not needed
[debian/dhcpd-pools.git] / src / dhcpd-pools.h
1 /* http://dhcpd-pools.sourceforge.net/
2 ** Copyright 2006- Sami Kerola <kerolasa@iki.fi>
3 **
4 ** This program is free software: you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation, either version 3 of the License, or
7 ** (at your option) any later version.
8 **
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ** GNU General Public License for more details.
13 **
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program.  If not, see <http://www.gnu.org/licenses/>.   
16 */
17
18 #ifndef DHCPD_POOLS_H
19 # define DHCPD_POOLS_H 1
20
21 #include <config.h>
22
23 /* Feature test switches */
24 #define _POSIX_SOURCE 1
25 #define POSIXLY_CORRECT 1
26
27 #ifdef  HAVE_STDLIB_H
28 #include <stdlib.h>
29 #else
30 extern void exit();
31 extern char *malloc();
32 #endif                          /* STDC_HEADERS */
33
34 /* Structures and unions */
35 struct configuration_t {
36         char *dhcpdconf_file;
37         char *dhcpdlease_file;
38         char output_format[2];
39         char sort[6];
40         int reverse_order;
41         char *output_file;
42         int output_limit[2];
43 };
44 struct shared_network_t {
45         char *name;
46         unsigned long int available;
47         unsigned long int used;
48         unsigned long int touched;
49         unsigned long int backups;
50 };
51 struct range_t {
52         struct shared_network_t *shared_net;
53         unsigned long int first_ip;
54         unsigned long int last_ip;
55         unsigned long int count;
56         unsigned long int touched;
57         unsigned long int backups;
58 };
59 struct macaddr_t {
60         char *ethernet;
61         char *ip;
62         struct macaddr_t *next;
63 };
64
65 /* Global variables */
66 static int const true = 1;
67 static int const false = 0;
68
69 struct configuration_t config;
70
71 static int const output_limit_bit_1 = 1;
72 static int const output_limit_bit_2 = 2;
73 static int const output_limit_bit_3 = 4;
74 unsigned int fullhtml;
75
76 struct shared_network_t *shared_networks;
77 char *shared_net_names;
78 unsigned int num_shared_networks;
79
80 struct range_t *ranges;
81 unsigned int num_ranges;
82
83 unsigned long int *leases;
84 unsigned long int num_leases;
85
86 unsigned long int *touches;
87 unsigned long int num_touches;
88
89 unsigned long int *backups;
90 unsigned long int num_backups;
91
92 struct macaddr_t *macaddr;
93
94 /* Function prototypes */
95 int prepare_memory(void);
96 int parse_leases(void);
97 char *parse_config(int, char *, char *, char *, struct shared_network_t *)
98     __attribute__ ((nonnull(2, 3, 4)));
99 int nth_field(int n, char *dest, const char *src)
100     __attribute__ ((nonnull(2, 3)))
101 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
102     __attribute__ ((__hot__))
103 #endif
104     ;
105 int prepare_data(void);
106 int do_counting(void);
107 void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges)
108     __attribute__ ((nonnull(1, 2)));
109 /* General support functions */
110 void *safe_malloc(const size_t size)
111 #if __GNUC__ >= 3
112     __attribute__ ((__malloc__))
113 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
114     __attribute__ ((__alloc_size__((1))))
115 #endif
116 #endif
117     ;
118 char *safe_strdup(const char *str) __attribute__ ((nonnull(1)));
119 void print_version(void) __attribute__ ((noreturn));
120 void usage(int status) __attribute__ ((noreturn));
121 /* qsort required functions... */
122 /* ...for ranges and... */
123 int intcomp(const void *x, const void *y) __attribute__ ((nonnull(1, 2)));
124 int rangecomp(const void *r1, const void *r2)
125     __attribute__ ((nonnull(1, 2)));
126 /* sort function pointer and functions */
127 int sort_name(void);
128 unsigned long int (*returner) (struct range_t r);
129 unsigned long int ret_ip(struct range_t r);
130 unsigned long int ret_cur(struct range_t r);
131 unsigned long int ret_max(struct range_t r);
132 unsigned long int ret_percent(struct range_t r);
133 unsigned long int ret_touched(struct range_t r);
134 unsigned long int ret_tc(struct range_t r);
135 unsigned long int ret_tcperc(struct range_t r);
136 void field_selector(char c);
137 int get_order(struct range_t *left, struct range_t *right)
138     __attribute__ ((nonnull(1, 2)));
139 void mergesort_ranges(struct range_t *orig, int size, struct range_t *temp)
140     __attribute__ ((nonnull(1, 3)));
141 /* output function pointer and functions */
142 int (*output_analysis) (void);
143 int output_txt(void);
144 int output_html(void);
145 int output_xml(void);
146 int output_csv(void);
147 /* Memory release, file closing etc */
148 void clean_up(void);
149
150 #endif                          /* DHCPD_POOLS_H */