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