<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -4,5 +4,8 @@ skeleton server. :-)
 Mark Andrews &lt;Mark_Andrews@isc.org&gt; pointed out several bugs and
 mistakes in some of the replies the server sent.
 
+Guillaume Filion fixed bugs and experimented with using BGP data
+intead of Geo::IP.
+
 MaxMind (http://www.maxmind.com/) provides us with excellent geo data
 and open source libraries to access it.</diff>
      <filename>CREDITS</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,9 @@
 
-See the SVN history for now :-)
 
-We'll track &quot;user visible changes&quot; here when we start making proper releases some day.
+   - read .json data files (to bulk save/load configuration)
+   - support __END__ to stop reading a configuration file
+   - max_hosts configuration (should probably be renamed?)
+   - Fix bug that disallowed setting default serial/ttl/primary_ns variables
+
+  r347 - 
+     - see SVN history for history prior to this. :-)
\ No newline at end of file</diff>
      <filename>Changes</filename>
    </modified>
    <modified>
      <diff>@@ -22,7 +22,8 @@ ftphost 192.0.2.5   ftp.dk ftp.europe
 #ns ns1.example.org
 #ns ns2.example.org
 #ttl 300
-#serial 2000  
+#serial 2000 
+#max_hosts 3  
 #include config/example.net
 
 </diff>
      <filename>config/base.sample</filename>
    </modified>
    <modified>
      <diff>@@ -5,8 +5,9 @@ use Countries qw(continent);
 use Geo::IP;
 use List::Util qw/max/;
 use Carp;
+use JSON qw();
 
-my $VERSION = ('$Rev: 347 $' =~ m/(\d+)/)[0];
+our $VERSION = ('$Rev: 347 $' =~ m/(\d+)/)[0];
 my $HeadURL = ('$HeadURL: http://svn.develooper.com/repos/pgeodns/trunk/pgeodns.pl $' =~ m!http:(//[^/]+.*)/pgeodns.pl!)[0];
 
 my $config;
@@ -20,10 +21,6 @@ sub new {
   bless \%args, $class;
 }
 
-sub log {
-  carp @_;
-}
-
 sub config {
   my ($self, $base) = @_;
   return $config unless $base;
@@ -114,7 +111,7 @@ sub reply_handler {
     push @ans, grep { $_-&gt;address eq $config_base-&gt;{ns}-&gt;{$qname} } @{ ($self-&gt;get_ns_records($config_base))[1] };
     @add = grep { $_-&gt;address ne $config_base-&gt;{ns}-&gt;{$qname} } @add;
     return ('NOERROR', \@ans, \@auth, \@add, { aa =&gt; 1 });
-  }
+ }
 
   elsif ($qname =~ m/^status\.\Q$base\E$/) {
     my $uptime = time - $stats-&gt;{started} || 1;
@@ -155,7 +152,7 @@ sub get_soa_record {
   my ($self, $config_base) = @_;
     Net::DNS::RR-&gt;new
 	(&quot;$config_base-&gt;{base}. 3600 IN SOA $config_base-&gt;{primary_ns};
-          dns.perl.org. $config_base-&gt;{serial} 5400 5400 2419200 $config_base-&gt;{ttl}&quot;);
+          support.bitnames.com. $config_base-&gt;{serial} 5400 5400 2419200 $config_base-&gt;{ttl}&quot;);
 }
 
 sub pick_groups {
@@ -185,19 +182,22 @@ sub pick_groups {
 sub pick_hosts {
   my ($self, $config_base, $group) = @_;
 
-  return unless $config_base-&gt;{groups}-&gt;{$group}; 
+  return unless $config_base-&gt;{groups}-&gt;{$group} and $config_base-&gt;{groups}-&gt;{$group}-&gt;{servers}; 
 
   my @answer;
-  my $max = 2;
-  $max = 1 unless scalar @{ $config_base-&gt;{groups}-&gt;{$group} };
+  my $max = $config_base-&gt;{max_hosts} || 2;
+  $max = 1 unless scalar @{ $config_base-&gt;{groups}-&gt;{$group}-&gt;{servers} };
 
   my $loop = 0;
 
   while (@answer &lt; $max) {
     last if ++$loop &gt; 10;  # bad configuration could make us loop ...
-    my ($host) = ( @{ $config_base-&gt;{groups}-&gt;{$group} } )[rand scalar @{ $config_base-&gt;{groups}-&gt;{$group} }];
+    my ($host) = ( @{ $config_base-&gt;{groups}-&gt;{$group}-&gt;{servers} }
+                 )[rand scalar @{ $config_base-&gt;{groups}-&gt;{$group}-&gt;{servers} }];
+    ($host, my $priority) = @$host;
     next if grep { $host eq $_-&gt;{name} } @answer;
-    push @answer, ({ name =&gt; $host, ip =&gt; $config_base-&gt;{hosts}-&gt;{$host}-&gt;{ip} });
+    my $ip = $host =~ m/^\d{1,3}(.\d{1,3}){3}$/ ? $host : $config_base-&gt;{hosts}-&gt;{$host}-&gt;{ip};
+    push @answer, ({ name =&gt; $host, ip =&gt; $ip });
   }
 
   @answer;
@@ -221,6 +221,8 @@ sub load_config {
 
   read_config( shift || 'pgeodns.conf' );
 
+  delete $config-&gt;{base};
+
   # warn Data::Dumper-&gt;Dump([\$config], [qw(config)]);
 
   # the default serial is timestamp of the newest config file. 
@@ -254,10 +256,10 @@ sub read_config {
     die &quot;Oops, recursive inclusion of $file - parent(s): &quot;, join &quot;, &quot;, @config_file_stack;
   }
 
-  push @config_file_stack, $file;
-
   open my $fh, $file
-    or &amp;log(&quot;Can't open config file: $file: $!&quot;);
+    or warn &quot;Can't open config file: $file: $!\n&quot; and return;
+
+  push @config_file_stack, $file;
 
   push @{ $config-&gt;{files} }, [$file, (stat($file))[9]];
 
@@ -266,11 +268,20 @@ sub read_config {
     s/^\s+//;
     s/\s+$//;
     next if /^\#/ or /^$/;
+    last if /^__END__$/;
 
     if (s/^base\s+//) {
-      $_ .= '.' unless m/\.$/;
-      $config-&gt;{base} = $_;
-      $config-&gt;{bases}-&gt;{$_} ||= { base =&gt; $_ };
+      my ($base_name, $json_file) = split /\s+/, $_;
+      $base_name .= '.' unless $base_name =~ m/\.$/;
+      $config-&gt;{base} = $base_name;
+      if ($json_file) {
+          open my $json_fh, $json_file or warn &quot;Could not open $json_file: $!\n&quot; and next;
+          push @{ $config-&gt;{files} }, [$json_file, (stat($json_file))[9]];
+          my $json = eval { local $/ = undef; &lt;$json_fh&gt; };
+          close $json_fh;
+          $config-&gt;{bases}-&gt;{$base_name} = JSON::jsonToObj($json);
+      }
+      $config-&gt;{bases}-&gt;{$base_name}-&gt;{base} ||= $base_name;
       next;
     }
     elsif (s/^include\s+//) {
@@ -289,6 +300,7 @@ sub read_config {
       }
       elsif (s/^(serial|ttl|primary_ns)\s+//) {
 	$config-&gt;{$1} = $_;
+        next;
       }
     }
 
@@ -306,18 +318,19 @@ sub read_config {
       $config_base-&gt;{primary_ns} = $name
 	unless $config_base-&gt;{primary_ns};
     }
-    elsif (s/^(serial|ttl|primary_ns)\s+//) {
+    elsif (s/^(serial|ttl|primary_ns|max_hosts)\s+//) {
       $config_base-&gt;{$1} = $_;
     }
     else {
       s/^\s*10+\s+//;
       my ($host, $ip, $groups) = split(/\s+/,$_,3);
+      die &quot;Bad configuration line: [$_]\n&quot; unless $groups; 
       $host = &quot;$host.&quot; unless $host =~ m/\.$/;
       $config_base-&gt;{hosts}-&gt;{$host} = { ip =&gt; $ip };
       for my $group_name (split /\s+/, $groups) {
 	$group_name = '' if $group_name eq '@';
-	$config_base-&gt;{groups}-&gt;{$group_name} ||= [];
-	push @{$config_base-&gt;{groups}-&gt;{$group_name}}, $host;
+	$config_base-&gt;{groups}-&gt;{$group_name}-&gt;{servers} ||= [];
+	push @{$config_base-&gt;{groups}-&gt;{$group_name}-&gt;{servers}}, [ $host, 1 ];
       }
     }
   }</diff>
      <filename>lib/GeoDNS.pm</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,9 @@
 
 include config/dist/base
 
-#include config/base
+# include config/jsontest
+
+# include config/base
 # include config/cpan
 
 </diff>
      <filename>pgeodns.conf</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d9965b4dc075fe4c89e1695ce1d33946f53c9f6a</id>
    </parent>
  </parents>
  <author>
    <name>Ask Bj&#248;rn Hansen</name>
    <email>ask@develooper.com</email>
  </author>
  <url>http://github.com/abh/pgeodns/commit/015a49fbd521759aef23a50ce2d8366587c81cd6</url>
  <id>015a49fbd521759aef23a50ce2d8366587c81cd6</id>
  <committed-date>2007-08-27T22:04:34-07:00</committed-date>
  <authored-date>2007-08-27T22:04:34-07:00</authored-date>
  <message>- read .json data files (to bulk save/load configuration)
    - support __END__ to stop reading a configuration file
    - max_hosts configuration (should probably be renamed?)
    - Fix bug that disallowed setting default serial/ttl/primary_ns variables
 


git-svn-id: https://svn.develooper.com/projects/pgeodns/trunk@531 e01dd7d5-6be1-0310-aa60-dbbdb055a346</message>
  <tree>4097f023d8acb5fe817211be1d4065eee99b1dde</tree>
  <committer>
    <name>Ask Bj&#248;rn Hansen</name>
    <email>ask@develooper.com</email>
  </committer>
</commit>
