The xml output is dirty and marked as FIXME
[debian/dhcpd-pools.git] / src / getdata.c
index ae3bc38..430468c 100644 (file)
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2006- Sami Kerola <   >
+** Copyright (C) 2006- Sami Kerola <kerolasa@iki.fi>
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -49,7 +49,6 @@ extern char *malloc();
 #include <fcntl.h>
 #include <errno.h>
 #include <ctype.h>
-#include <limits.h>
 
 #include "dhcpd-pools.h"
 #include "defaults.h"
@@ -135,21 +134,21 @@ int parse_leases(void)
                        num_backups++;
                }
 
-               if ((sw_active_lease == 1)
+               /* FIXME: move to output.c and use FILE *outfile */
+               if ((config.output_format[0] == 'X')
+                   && (sw_active_lease == 1)
                    && (strstr(line, "hardware ethernet"))) {
                        nth_field(3, macstring, line);
                        macstring[strlen(macstring) - 1] = '\0';
 
-                       if (config.output_format[0] == 'X') {
-                               printf
-                                   ("<active_lease>\n\t<ip>%s</ip>\n\t<macaddress>%s</macaddress>\n</active_lease>\n",
-                                    ipstring, macstring);
-                       };
+                        printf
+                           ("<active_lease>\n\t<ip>%s</ip>\n\t<macaddress>%s</macaddress>\n</active_lease>\n",
+                            ipstring, macstring);
                }
 
-               if ((num_leases > leasesmallocsize) ||
-                   (num_touches > touchesmallocsize) ||
-                   (num_backups > backupsmallocsize)) {
+               if ((leasesmallocsize < num_leases) ||
+                   (touchesmallocsize < num_touches) ||
+                   (backupsmallocsize < num_backups)) {
                        printf("WARNING: running out of memory\n");
                        printf("\tlease/touch/backup = %lu/%lu/%lu\n",
                               leasesmallocsize, touchesmallocsize,
@@ -351,7 +350,7 @@ char *parse_config(int is_include, char *config_file,
                        i++;
                        /* Long word which is almost causing overflow. Not any of words
                         * this program is looking for are this long. */
-                       if (i > MAXLEN) {
+                       if (MAXLEN < i) {
                                newclause = false;
                                i = 0;
                                continue;
@@ -415,7 +414,7 @@ char *parse_config(int is_include, char *config_file,
                                range_p->backups = 0;
                                range_p->shared_net = shared_p;
                                num_ranges++;
-                               if (num_ranges > RANGES) {
+                               if (RANGES < num_ranges) {
                                        eprintf
                                            ("parse_config: Range space full! Increase RANGES and recompile.");
                                        exit(EXIT_FAILURE);
@@ -425,19 +424,19 @@ char *parse_config(int is_include, char *config_file,
                        case 3:
                                /* printf ("range 1nd ip: %s\n", word); */
                                range_p = ranges + num_ranges;
-                               inet_aton(word, &inp);
-                               range_p->first_ip = htonl(inp.s_addr) - 1;
-                               if (range_p->first_ip == UINT_MAX) {
+                               if (!(inet_aton(word, &inp))) {
                                        /* word was not ip, try again */
                                        break;
                                }
+                               range_p->first_ip = htonl(inp.s_addr) - 1;
                                argument = 2;
                                break;
                        case 4:
                                /* printf ("include file: %s\n", word); */
                                argument = 0;
                                next_free_shared_name =
-                                   parse_config(false, word, current_shared_name,
+                                   parse_config(false, word,
+                                                current_shared_name,
                                                 next_free_shared_name,
                                                 shared_p);
                                newclause = true;