Index: branches/stable/tiny-import.pl
===================================================================
--- branches/stable/tiny-import.pl	(revision 545)
+++ branches/stable/tiny-import.pl	(revision 547)
@@ -27,9 +27,7 @@
 
 use lib '.';
-use DNSDB qw(:ALL);
-
-if (!loadConfig()) {
-  warn "Using default configuration;  unable to load custom settings: $DNSDB::errstr";
-}
+use DNSDB;
+
+my $dnsdb = new DNSDB;
 
 usage() if !@ARGV;
@@ -77,6 +75,5 @@
 
 my $code;
-my ($dbh,$msg) = connectDB($config{dbname}, $config{dbuser}, $config{dbpass}, $config{dbhost});
-initGlobals($dbh) if $dbh;
+my $dbh = $dnsdb->{dbh};
 
 $dbh->{AutoCommit} = 0;
@@ -85,4 +82,5 @@
 my %cnt;
 my @deferred;
+my $converted = 0;
 my $errstr = '';
 
@@ -167,7 +165,7 @@
 
   # .. but we can at least say how many records weren't imported.
-  print "$ok OK, ".scalar(@deferred)." deferred records in $flatfile\n";
-  $#deferred = -1;
-
+  print "$ok OK, ".scalar(@deferred)." deferred, $converted downconverted records in $flatfile\n";
+  undef @deferred;
+  $converted = 0;
 
   # Sub for various nonstandard types with lots of pure bytes expressed in octal
@@ -250,4 +248,5 @@
     my $nodefer = shift || 0;
     my $impok = 1;
+    my $msg;
 
     $errstr = $rec;  # this way at least we have some idea what went <splat>
@@ -268,12 +267,18 @@
       $loc = '' if !$loc;
       $loc = '' if $loc =~ /^:+$/;
-      my $fparent = DNSDB::_hostparent($dbh, $host);
+      my $fparent = $dnsdb->_hostparent($host);
       my ($rparent) = $dbh->selectrow_array("SELECT rdns_id FROM revzones WHERE revnet >> ?", undef, ($ip));
       if ($fparent && $rparent) {
 	$recsth->execute($fparent, $rparent, $host, 65280, $ip, 0, 0, 0, $ttl, $loc);
       } else {
-	push @deferred, $rec unless $nodefer;
-	$impok = 0;
-	#  print "$tmporig deferred;  can't find both forward and reverse zone parents\n";
+	if ($importcfg{conv}) {
+	  # downconvert A+PTR if forward zone is not found
+	  $recsth->execute(0, $rparent, $host, 12, $ip, 0, 0, 0, $ttl, $loc);
+	  $converted++;
+	} else {
+	  push @deferred, $rec unless $nodefer;
+	  $impok = 0;
+	  #  print "$tmporig deferred;  can't find both forward and reverse zone parents\n";
+	}
       }
 
@@ -301,5 +306,5 @@
 
       } else {
-	my $fparent = DNSDB::_hostparent($dbh, $host);
+	my $fparent = $dnsdb->_hostparent($host);
 	if ($fparent) {
 	  $recsth->execute($fparent, 0, $host, 5, $targ, 0, 0, 0, $ttl, $loc);
@@ -337,5 +342,5 @@
 	}
       } else {
-	my $fparent = DNSDB::_hostparent($dbh, $zone);
+	my $fparent = $dnsdb->_hostparent($zone);
 	if ($fparent) {
 	  $recsth->execute($fparent, 0, $zone, 2, $ns, 0, 0, 0, $ttl, $loc);
@@ -389,5 +394,5 @@
       $loc = '' if $loc =~ /^:+$/;
 
-      my $domid = DNSDB::_hostparent($dbh, $host);
+      my $domid = $dnsdb->_hostparent($host);
       if ($domid) {
 	$recsth->execute($domid, 0, $host, 1, $ip, 0, 0, 0, $ttl, $loc);
@@ -440,5 +445,5 @@
 
       # allow for subzone MXes, since it's perfectly legitimate to simply stuff it all in a single parent zone
-      my $domid = DNSDB::_hostparent($dbh, $zone);
+      my $domid = $dnsdb->_hostparent($zone);
       if ($domid) {
 	$recsth->execute($domid, 0, $zone, 15, $host, $dist, 0, 0, $ttl, $loc);
@@ -466,5 +471,5 @@
 	$recsth->execute(0, $rparent, $rdata, 16, "$msg", 0, 0, 0, $ttl, $loc);
       } else {
-	my $domid = DNSDB::_hostparent($dbh, $fqdn);
+	my $domid = $dnsdb->_hostparent($fqdn);
 	if ($domid) {
 	  $recsth->execute($domid, 0, $fqdn, 16, $rdata, 0, 0, 0, $ttl, $loc);
@@ -581,5 +586,5 @@
 #  }
 
-	my $domid = DNSDB::_hostparent($dbh, $fqdn);
+	my $domid = $dnsdb->_hostparent($fqdn);
 	if ($domid) {
 	  $recsth->execute($domid, 0, $fqdn, 33, $target, $prio, $weight, $port, $ttl, $loc) if $domid;
@@ -599,5 +604,5 @@
 	my $val = NetAddr::IP->new(join(':', @v6));
 
-	my $fparent = DNSDB::_hostparent($dbh, $fqdn);
+	my $fparent = $dnsdb->_hostparent($fqdn);
 	if ($fparent) {
 	  $recsth->execute($fparent, 0, $fqdn, 28, $val->addr, 0, 0, 0, $ttl, $loc);
@@ -621,5 +626,5 @@
 	  }
 	} else {
-	  my $domid = DNSDB::_hostparent($dbh, $fqdn);
+	  my $domid = $dnsdb->_hostparent($fqdn);
 	  if ($domid) {
 	    $recsth->execute($domid, 0, $fqdn, 16, $txtstring, 0, 0, 0, $ttl, $loc);
@@ -649,5 +654,5 @@
 	  }
 	} else {
-	  my $domid = DNSDB::_hostparent($dbh, $fqdn);
+	  my $domid = $dnsdb->_hostparent($fqdn);
 	  if ($domid) {
 	    $recsth->execute($domid, 0, $fqdn, 17, "$email $txtrec", 0, 0, 0, $ttl, $loc);
@@ -665,5 +670,5 @@
 
 	# these do not make sense in a reverse zone, since they're logically attached to an A record
-	my $domid = DNSDB::_hostparent($dbh, $fqdn);
+	my $domid = $dnsdb->_hostparent($fqdn);
 	if ($domid) {
 	  $recsth->execute($domid, 0, $fqdn, 44, $sshfp, 0, 0, 0, $ttl, $loc);
