--- loncom/lonnet/perl/lonnet.pm 2009/03/09 05:25:44 1.990 +++ loncom/lonnet/perl/lonnet.pm 2009/04/11 14:47:51 1.993 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.990 2009/03/09 05:25:44 raeburn Exp $ +# $Id: lonnet.pm,v 1.993 2009/04/11 14:47:51 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -74,9 +74,7 @@ use strict; use LWP::UserAgent(); use HTTP::Date; use Image::Magick; -use IO::Socket; -# use Date::Parse; use vars qw(%perlvar %spareid %pr %prp $memcache %packagetab $tmpdir $_64bit %env %protocol); @@ -198,6 +196,33 @@ sub get_server_timezone { } } +sub get_server_loncaparev { + my ($dom,$lonhost) = @_; + if (defined($lonhost)) { + if (!defined(&hostname($lonhost))) { + undef($lonhost); + } + } + if (!defined($lonhost)) { + if (defined(&domain($dom,'primary'))) { + $lonhost=&domain($dom,'primary'); + if ($lonhost eq 'no_host') { + undef($lonhost); + } + } + } + if (defined($lonhost)) { + my $cachetime = 24*3600; + my ($loncaparev,$cached)=&is_cached_new('serverloncaparev',$lonhost); + if (defined($cached)) { + return $loncaparev; + } else { + my $loncaparev = &reply('serverloncaparev',$lonhost); + return &do_cache_new('serverloncaparev',$lonhost,$loncaparev,$cachetime); + } + } +} + # -------------------------------------------------- Non-critical communication sub subreply { my ($cmd,$server)=@_; @@ -9048,23 +9073,31 @@ sub get_dns { return %iphost; } -} -# -# Given a DNS returns the loncapa host name for that DNS -# -sub host_from_dns { - my ($dns) = @_; - my @hosts; - my $ip; - - $ip = gethostbyname($dns); # Initial translation to IP is in net order. - if (length($ip) == 4) { - $ip = &IO::Socket::inet_ntoa($ip); - @hosts = get_hosts_from_ip($ip); - return $hosts[0]; + # + # Given a DNS returns the loncapa host name for that DNS + # + sub host_from_dns { + my ($dns) = @_; + my @hosts; + my $ip; + + if (exists($name_to_ip{$dns})) { + $ip = $name_to_ip{$dns}; + } + if (!$ip) { + $ip = gethostbyname($dns); # Initial translation to IP is in net order. + if (length($ip) == 4) { + $ip = &IO::Socket::inet_ntoa($ip); + } + } + if ($ip) { + @hosts = get_hosts_from_ip($ip); + return $hosts[0]; + } + return undef; } - return undef; + } BEGIN {