Index: /trunk/cgi-bin/ipdb-rpc.cgi
===================================================================
--- /trunk/cgi-bin/ipdb-rpc.cgi	(revision 667)
+++ /trunk/cgi-bin/ipdb-rpc.cgi	(revision 668)
@@ -46,7 +46,46 @@
 
 my $methods = {
-#	'ipdb.getCityList'	=> \&rpc_getCityList,
+	# Internal core IPDB subs;  no value in exposing them since the DB handle can't be used by the caller
+	#'ipdb._rpc'
+	# This one could be exposed, but the globals aren't automatically
+	# inherited by the caller anyway, and we call it just above locally.
+	#'ipdb.initIPDBGlobals'
+	#'ipdb.connectDB'
+	#'ipdb.finish'
+	#'ipdb.checkDBSanity'
+	'ipdb.addMaster'	=>	\&rpc_addMaster,
+	'ipdb.touchMaster'	=>	\&rpc_touchMaster,
+	'ipdb.listSummary'	=>	\&rpc_listSummary,
+	'ipdb.listSubs'	=>	\&rpc_listSubs,
+	'ipdb.listContainers'	=>	\&rpc_listContainers,
+	'ipdb.listAllocations'	=>	\&rpc_listAllocations,
+	'ipdb.listFree'	=>	\&rpc_listFree,
+	'ipdb.listPool'	=>	\&rpc_listPool,
+	'ipdb.getMasterList'	=>	\&rpc_getMasterList,
+	'ipdb.getTypeList'	=>	\&rpc_getTypeList,
+	'ipdb.getPoolSelect'	=>	\&rpc_getPoolSelect,
+	'ipdb.findAllocateFrom'	=>	\&rpc_findAllocateFrom,
+	'ipdb.ipParent'	=>	\&rpc_ipParent,
+	'ipdb.subParent'	=>	\&rpc_subParent,
+	'ipdb.blockParent'	=>	\&rpc_blockParent,
+	'ipdb.getRoutedCity'	=>	\&rpc_getRoutedCity,
+	'ipdb.allocateBlock'	=>	\&rpc_allocateBlock,
+	# another internal sub;  mainly a sub to make allocateBlock() a lot smaller
+	#'ipdb.initPool'	=>	\&rpc_initPool
+	'ipdb.updateBlock'	=>	\&rpc_updateBlock,
+	'ipdb.deleteBlock'	=>	\&rpc_deleteBlock,
+	'ipdb.getBlockData'	=>	\&rpc_getBlockData,
+	'ipdb.getBlockRDNS'	=>	\&rpc_getBlockRDNS,
+	'ipdb.getNodeList'	=>	\&rpc_getNodeList,
+	'ipdb.getNodeName'	=>	\&rpc_getNodeName,
+	'ipdb.getNodeInfo'	=>	\&rpc_getNodeInfo,
+	'ipdb.mailNotify'	=>	\&rpc_mailNotify,
+
+# Subs not part of the core IPDB
+	'ipdb.getDispAlloctypes'	=> \&rpc_getDispAlloctypes,
+	'ipdb.getListAlloctypes'	=> \&rpc_getListAlloctypes,
+	'ipdb.getDefCustIDs'	=> \&rpc_getDefCustIDs,
+	'ipdb.getCityList'	=> \&rpc_getCityList,
 	'ipdb.getAvailableStatics'	=> \&rpc_getAvailableStatics,
-	'ipdb.allocateBlock'	=>	\&rpc_allocateBlock,
 };
 
@@ -138,37 +177,31 @@
 ##
 
+# Core IPDB subs
 # Prefixed with rpc_ to not conflict with subs in IPDB.pm
 
-sub rpc_getCityList {
-  my %args = @_;
-
-  _commoncheck(\%args, 'n');
-}
-
-# Get a list of available static IPs of the given type
-sub rpc_getAvailableStatics {
-  my %args = @_;
-
-  _commoncheck(\%args, 'n');
-
-  my ($base,undef) = split //, $args{type};
-  $base .= "_";
-  my @params = ($base);
-
-  # IPDB 2.7
-  my $sql = "SELECT 0 AS id,poolips.ip,0 AS parent_id,pool ".
-  "FROM poolips JOIN allocations ON poolips.pool=allocations.cidr WHERE poolips.type LIKE ?";
-
-  $sql .= " AND allocations.city=?" if $base ne 'd_';
-  push @params, $args{city} if $base ne 'd_';
-
-  $sql .= " AND poolips.available='y'";
-
-  my $ret = $ip_dbh->selectall_arrayref($sql, { Slice => {} }, (@params) );
-  # IPDB 3.0
-  #my $ret = $ipdb->getIPList(arg arg arg);
-  die $ip_dbh->errstr if !$ret;
-  return $ret;
-} # rpc_getAvailableStatics()
+# These are deep internals and don't make much sense to expose, since RPC
+# by definition does not access the backing DB directly.
+#sub _rpc {}
+#sub initIPDBGlobals {}
+#sub connectDB {}
+#sub finish {}
+#sub checkDBSanity {}
+
+sub rpc_addMaster {}
+sub rpc_touchMaster {}
+sub rpc_listSummary {}
+sub rpc_listSubs {}
+sub rpc_listContainers {}
+sub rpc_listAllocations {}
+sub rpc_listFree {}
+sub rpc_listPool {}
+sub rpc_getMasterList {}
+sub rpc_getTypeList {}
+sub rpc_getPoolSelect {}
+sub rpc_findAllocateFrom {}
+sub rpc_ipParent {}
+sub rpc_subParent {}
+sub rpc_blockParent {}
+sub rpc_getRoutedCity {}
 
 sub rpc_allocateBlock {
@@ -209,2 +242,90 @@
   return $msg;
 } # rpc_allocateBlock()
+
+# another internal sub;  mainly a sub to make allocateBlock() a lot smaller
+#sub rpc_initPool {}
+sub rpc_updateBlock {}
+sub rpc_deleteBlock {}
+sub rpc_getBlockData {}
+sub rpc_getBlockRDNS {}
+sub rpc_getNodeList {}
+sub rpc_getNodeName {}
+sub rpc_getNodeInfo {}
+sub rpc_mailNotify {}
+
+
+##
+## Subs not part of the core IPDB
+##
+
+# Subs to send back IPDB globals
+
+#our %disp_alloctypes;
+sub rpc_getDispAlloctypes {
+  my %args = @_;
+  _commoncheck(\%args, 'n');
+  return \%disp_alloctypes;
+}
+
+#our %list_alloctypes;
+sub rpc_getListAlloctypes {
+  my %args = @_;
+  _commoncheck(\%args, 'n');
+  return \%list_alloctypes;
+}
+
+#our %def_custids;
+sub rpc_getDefCustIDs {
+  my %args = @_;
+  _commoncheck(\%args, 'n');
+  return \%def_custids;
+}
+
+#our @citylist;
+sub rpc_getCityList {
+  my %args = @_;
+  _commoncheck(\%args, 'n');
+  return \@citylist;
+}
+
+#our @poplist;
+sub rpc_getPOPList {
+  my %args = @_;
+  _commoncheck(\%args, 'n');
+  return \@poplist;
+}
+
+# not sure how useful it is to expose this on RPC
+#our %IPDBacl;
+sub rpc_getIPDBacl {
+  my %args = @_;
+  _commoncheck(\%args, 'n');
+  return \%IPDBacl;
+}
+
+# Operations not provided directly by the core IPDB
+
+# Get a list of available static IPs of the given type
+# Not a core IPDB sub since there's little use for this format.
+sub rpc_getAvailableStatics {
+  my %args = @_;
+
+  _commoncheck(\%args, 'n');
+
+  my ($base,undef) = split //, $args{type};
+  $base .= "_";
+  my @params = ($base);
+
+  my $sql = "SELECT poolips.id,poolips.ip,poolips.parent_id,poolips.pool ".
+	"FROM poolips JOIN allocations ON poolips.parent_id=allocations.id WHERE poolips.type LIKE ?";
+  if ($base ne 'd_' && $args{city}) {
+    $sql .= " AND allocations.city=?";
+    push @params, $args{city};
+  }
+  $sql .= " AND poolips.available='y'";
+
+  my $ret = $ip_dbh->selectall_arrayref($sql, { Slice => {} }, (@params) );
+  die $ip_dbh->errstr if !$ret;
+
+  return $ret;
+} # rpc_getAvailableStatics()
