Copyright notice change to GNU license 3
[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 /* Not STDC_HEADERS */
30 extern void exit ();
31 extern char *malloc ();
32 #endif /* STDC_HEADERS */
33
34 /* Structures and unions */
35 struct configuration_t
36 {
37   char *dhcpdconf_file;
38   char *dhcpdlease_file;
39   char output_format[2];
40   char sort[6];
41   int reverse_order;
42   char *output_file;
43   int output_limit[2];
44 };
45 struct shared_network_t
46 {
47   char *name;
48   unsigned long int available;
49   unsigned long int used;
50   unsigned long int touched;
51   unsigned long int backups;
52 };
53 struct range_t
54 {
55   struct shared_network_t *shared_net;
56   unsigned long int first_ip;
57   unsigned long int last_ip;
58   unsigned long int count;
59   unsigned long int touched;
60   unsigned long int backups;
61 };
62 /* Global variables */
63 static int const true = 1;
64 static int const false = 0;
65
66 struct configuration_t config;
67
68 static int const output_limit_bit_1 = 1;
69 static int const output_limit_bit_2 = 2;
70 static int const output_limit_bit_3 = 4;
71 unsigned int fullhtml;
72
73 struct shared_network_t *shared_networks;
74 char *shared_net_names;
75 unsigned int num_shared_networks;
76
77 struct range_t *ranges;
78 unsigned int num_ranges;
79
80 unsigned long int *leases;
81 unsigned long int num_leases;
82
83 unsigned long int *touches;
84 unsigned long int num_touches;
85
86 unsigned long int *backups;
87 unsigned long int num_backups;
88
89 /* Function prototypes */
90 int prepare_memory (void);
91 int parse_leases (void);
92 char * parse_config (int, char *, char *, char *, struct shared_network_t *);
93 int nth_field (int n, char *dest, const char *src);
94 int prepare_data (void);
95 int do_counting (void);
96 void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges);
97 /* General support functions */
98 void *safe_malloc (const size_t size);
99 void print_version (void);
100 void usage (int status);
101 /* qsort required functions... */
102 /* ...for ranges and... */
103 int intcomp (const void *x, const void *y);
104 int rangecomp (const void *r1, const void *r2);
105 /* sort function pointer and functions */
106 int sort_name (void);
107 unsigned long int (*returner) (struct range_t r);
108 unsigned long int ret_ip(struct range_t r);
109 unsigned long int ret_cur(struct range_t r);
110 unsigned long int ret_max(struct range_t r);
111 unsigned long int ret_percent(struct range_t r);
112 unsigned long int ret_touched(struct range_t r);
113 unsigned long int ret_tc(struct range_t r);
114 unsigned long int ret_tcperc(struct range_t r);
115 void field_selector(char c);
116 int get_order(struct range_t *left, struct range_t *right);
117 void mergesort_ranges (struct range_t *orig, int size, struct range_t *temp);
118 /* output function pointer and functions */
119 int (*output_analysis) (void);
120 int output_txt (void);
121 int output_html (void);
122 int output_xml (void);
123 int output_csv (void);
124 /* Memory release, file closing etc */
125 void clean_up (void);
126
127 #endif /* DHCPD_POOLS_H */