Diff for /loncom/lonnet/perl/lonnet.pm between versions 1.419 and 1.424

version 1.419, 2003/09/19 18:20:35 version 1.424, 2003/09/25 20:25:04
Line 76  qw(%perlvar %hostname %homecache %badSer Line 76  qw(%perlvar %hostname %homecache %badSer
    %libserv %pr %prp %metacache %packagetab %titlecache      %libserv %pr %prp %metacache %packagetab %titlecache 
    %courselogs %accesshash %userrolehash $processmarker $dumpcount      %courselogs %accesshash %userrolehash $processmarker $dumpcount 
    %coursedombuf %coursenumbuf %coursehombuf %coursedescrbuf %courseresdatacache      %coursedombuf %coursenumbuf %coursehombuf %coursedescrbuf %courseresdatacache 
    %usectioncache %domaindescription %domain_auth_def %domain_auth_arg_def      %userresdatacache %usectioncache %domaindescription %domain_auth_def %domain_auth_arg_def 
    %domain_lang_def %domain_city %domain_longi %domain_lati $tmpdir);     %domain_lang_def %domain_city %domain_longi %domain_lati $tmpdir);
   
 use IO::Socket;  use IO::Socket;
Line 856  sub devalidate_cache { Line 856  sub devalidate_cache {
   
 sub is_cached {  sub is_cached {
     my ($cache,$id,$time) = @_;      my ($cache,$id,$time) = @_;
       if (!$time) { $time=300; }
     if (!exists($$cache{$id.'.time'})) {      if (!exists($$cache{$id.'.time'})) {
  return (undef,undef);   return (undef,undef);
     } else {      } else {
Line 878  sub usection { Line 879  sub usection {
     my ($udom,$unam,$courseid)=@_;      my ($udom,$unam,$courseid)=@_;
     my $hashid="$udom:$unam:$courseid";      my $hashid="$udom:$unam:$courseid";
           
     my ($result,$cached)=&is_cached(\%usectioncache,$hashid,300);      my ($result,$cached)=&is_cached(\%usectioncache,$hashid);
     if (defined($cached)) { return $result; }      if (defined($cached)) { return $result; }
     $courseid=~s/\_/\//g;      $courseid=~s/\_/\//g;
     $courseid=~s/^(\w)/\/$1/;      $courseid=~s/^(\w)/\/$1/;
Line 2219  sub currentdump { Line 2220  sub currentdump {
        return if ($tmp[0] =~ /^(error:|no_such_host)/);         return if ($tmp[0] =~ /^(error:|no_such_host)/);
        my %hash = @tmp;         my %hash = @tmp;
        @tmp=();         @tmp=();
        # Code ripped from lond, essentially.  The only difference         %returnhash = %{&convert_dump_to_currentdump(\%hash)};
        # here is the unescaping done by lonnet::dump().  Conceivably  
        # we might run in to problems with parameter names =~ /^v\./  
        while (my ($key,$value) = each(%hash)) {  
            my ($v,$symb,$param) = split(/:/,$key);  
            next if ($v eq 'version' || $symb eq 'keys');  
            next if (exists($returnhash{$symb}) &&  
                     exists($returnhash{$symb}->{$param}) &&  
                     $returnhash{$symb}->{'v.'.$param} > $v);  
            $returnhash{$symb}->{$param}=$value;  
            $returnhash{$symb}->{'v.'.$param}=$v;  
        }  
        #  
        # Remove all of the keys in the hashes which keep track of  
        # the version of the parameter.  
        while (my ($symb,$param_hash) = each(%returnhash)) {  
            # use a foreach because we are going to delete from the hash.  
            foreach my $key (keys(%$param_hash)) {  
                delete($param_hash->{$key}) if ($key =~ /^v\./);  
            }  
        }  
    } else {     } else {
        my @pairs=split(/\&/,$rep);         my @pairs=split(/\&/,$rep);
        foreach (@pairs) {         foreach (@pairs) {
Line 2252  sub currentdump { Line 2233  sub currentdump {
    return %returnhash;     return %returnhash;
 }  }
   
   sub convert_dump_to_currentdump{
       my %hash = %{shift()};
       my %returnhash;
       # Code ripped from lond, essentially.  The only difference
       # here is the unescaping done by lonnet::dump().  Conceivably
       # we might run in to problems with parameter names =~ /^v\./
       while (my ($key,$value) = each(%hash)) {
           my ($v,$symb,$param) = split(/:/,$key);
           next if ($v eq 'version' || $symb eq 'keys');
           next if (exists($returnhash{$symb}) &&
                    exists($returnhash{$symb}->{$param}) &&
                    $returnhash{$symb}->{'v.'.$param} > $v);
           $returnhash{$symb}->{$param}=$value;
           $returnhash{$symb}->{'v.'.$param}=$v;
       }
       #
       # Remove all of the keys in the hashes which keep track of
       # the version of the parameter.
       while (my ($symb,$param_hash) = each(%returnhash)) {
           # use a foreach because we are going to delete from the hash.
           foreach my $key (keys(%$param_hash)) {
               delete($param_hash->{$key}) if ($key =~ /^v\./);
           }
       }
       return \%returnhash;
   }
   
 # --------------------------------------------------------------- put interface  # --------------------------------------------------------------- put interface
   
 sub put {  sub put {
Line 3295  sub condval { Line 3303  sub condval {
     return $result;      return $result;
 }  }
   
   # ---------------------------------------------------- Devalidate courseresdata
   
   sub devalidatecourseresdata {
       my ($coursenum,$coursedomain)=@_;
       my $hashid=$coursenum.':'.$coursedomain;
       &devalidate_cache(\%courseresdatacache,$hashid);
   }
   
 # --------------------------------------------------- Course Resourcedata Query  # --------------------------------------------------- Course Resourcedata Query
   
 sub courseresdata {  sub courseresdata {
     my ($coursenum,$coursedomain,@which)=@_;      my ($coursenum,$coursedomain,@which)=@_;
     my $coursehom=&homeserver($coursenum,$coursedomain);      my $coursehom=&homeserver($coursenum,$coursedomain);
     my $hashid=$coursenum.':'.$coursedomain;      my $hashid=$coursenum.':'.$coursedomain;
     my ($result,$cached)=&is_cached(\%courseresdatacache,$hashid,300);      my ($result,$cached)=&is_cached(\%courseresdatacache,$hashid);
     unless (defined($cached)) {      unless (defined($cached)) {
  my %dumpreply=&dump('resourcedata',$coursedomain,$coursenum);   my %dumpreply=&dump('resourcedata',$coursedomain,$coursenum);
  $result=\%dumpreply;   $result=\%dumpreply;
Line 3485  sub EXT { Line 3501  sub EXT {
   
 # ----------------------------------------------------------- first, check user  # ----------------------------------------------------------- first, check user
     #most student don\'t have any data set, check if there is some data      #most student don\'t have any data set, check if there is some data
             #every thirty minutes  
     if (! &EXT_cache_status($udom,$uname)) {      if (! &EXT_cache_status($udom,$uname)) {
  my %resourcedata=&get('resourcedata',   my $hashid="$udom:$uname";
       [$courselevelr,$courselevelm,$courselevel],   my ($result,$cached)=&is_cached(\%userresdatacache,$hashid);
       $udom,$uname);   if (!defined($cached)) { 
  my ($tmp)=keys(%resourcedata);      my %resourcedata=&get('resourcedata',
     [$courselevelr,$courselevelm,
      $courselevel],$udom,$uname);
       $result=\%resourcedata;
    }
    my ($tmp)=keys(%$result);
  if (($tmp!~/^error\:/) && ($tmp!~/^con_lost/)) {   if (($tmp!~/^error\:/) && ($tmp!~/^con_lost/)) {
     if ($resourcedata{$courselevelr}) {      &do_cache(\%userresdatacache,$hashid,$result);
  return $resourcedata{$courselevelr}; }      if ($$result{$courselevelr}) {
     if ($resourcedata{$courselevelm}) {   return $$result{$courselevelr}; }
  return $resourcedata{$courselevelm}; }      if ($$result{$courselevelm}) {
     if ($resourcedata{$courselevel}) {   return $$result{$courselevelm}; }
  return $resourcedata{$courselevel}; }      if ($$result{$courselevel}) {
    return $$result{$courselevel}; }
  } else {   } else {
     if ($tmp!~/No such file/) {      if ($tmp!~/No such file/) {
  &logthis("<font color=blue>WARNING:".   &logthis("<font color=blue>WARNING:".
  " Trying to get resource data for ".   " Trying to get resource data for ".
  $uname." at ".$udom.": ".   $uname." at ".$udom.": ".
  $tmp."</font>");   $tmp."</font>");
    &do_cache(\%userresdatacache,$hashid,undef);
     } elsif ($tmp=~/error:No such file/) {      } elsif ($tmp=~/error:No such file/) {
                         &EXT_cache_set($udom,$uname);                          &EXT_cache_set($udom,$uname);
     } elsif ($tmp =~ /^(con_lost|no_such_host)/) {      } elsif ($tmp =~ /^(con_lost|no_such_host)/) {
    &do_cache(\%userresdatacache,$hashid,undef);
  return $tmp;   return $tmp;
     }      }
  }   }
Line 3613  sub add_prefix_and_part { Line 3636  sub add_prefix_and_part {
   
 sub metadata {  sub metadata {
     my ($uri,$what,$liburi,$prefix,$depthcount)=@_;      my ($uri,$what,$liburi,$prefix,$depthcount)=@_;
   
     $uri=&declutter($uri);      $uri=&declutter($uri);
     # if it is a non metadata possible uri return quickly      # if it is a non metadata possible uri return quickly
     if (($uri eq '') || (($uri =~ m|^/*adm/|) && ($uri !~ m|^adm/includes|)) ||      if (($uri eq '') || (($uri =~ m|^/*adm/|) && ($uri !~ m|^adm/includes|)) ||
         ($uri =~ m|/$|) || ($uri =~ m|/.meta$|)) {          ($uri =~ m|/$|) || ($uri =~ m|/.meta$|) || ($uri =~ /^~/) ||
    ($uri =~ m|home/[^/]+/public_html/|)) {
  return '';   return '';
     }      }
     my $filename=$uri;      my $filename=$uri;

Removed from v.1.419  
changed lines
  Added in v.1.424


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>