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

version 1.413, 2003/09/16 17:54:50 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 
    %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 85  use Apache::Constants qw(:common :http); Line 85  use Apache::Constants qw(:common :http);
 use HTML::LCParser;  use HTML::LCParser;
 use Fcntl qw(:flock);  use Fcntl qw(:flock);
 use Apache::loncoursedata;  use Apache::loncoursedata;
   use Apache::lonlocal;
   
 my $readit;  my $readit;
   
Line 847  sub getsection { Line 848  sub getsection {
     return '-1';      return '-1';
 }  }
   
   sub devalidate_cache {
       my ($cache,$id) = @_;
       delete $$cache{$id.'.time'};
       delete $$cache{$id};
   }
   
   sub is_cached {
       my ($cache,$id,$time) = @_;
       if (!$time) { $time=300; }
       if (!exists($$cache{$id.'.time'})) {
    return (undef,undef);
       } else {
    if (time-$$cache{$id.'.time'}>$time) {
       &devalidate_cache($cache,$id);
       return (undef,undef);
    }
       }
       return ($$cache{$id},1);
   }
   
   sub do_cache {
       my ($cache,$id,$value) = @_;
       $$cache{$id.'.time'}=time;
       # do_cache implictly return the set value
       $$cache{$id}=$value;
   }
   
 sub usection {  sub usection {
     my ($udom,$unam,$courseid)=@_;      my ($udom,$unam,$courseid)=@_;
       my $hashid="$udom:$unam:$courseid";
       
       my ($result,$cached)=&is_cached(\%usectioncache,$hashid);
       if (defined($cached)) { return $result; }
     $courseid=~s/\_/\//g;      $courseid=~s/\_/\//g;
     $courseid=~s/^(\w)/\/$1/;      $courseid=~s/^(\w)/\/$1/;
     foreach (split(/\&/,&reply('dump:'.$udom.':'.$unam.':roles',      foreach (split(/\&/,&reply('dump:'.$udom.':'.$unam.':roles',
Line 867  sub usection { Line 899  sub usection {
             if ($end) {              if ($end) {
                 if ($now>$end) { $notactive=1; }                  if ($now>$end) { $notactive=1; }
             }               } 
             unless ($notactive) { return $section; }              unless ($notactive) {
    return &do_cache(\%usectioncache,$hashid,$section);
       }
         }          }
     }      }
     return '-1';      return &do_cache(\%usectioncache,$hashid,'-1');
 }  }
   
 # ------------------------------------- Read an entry from a user's environment  # ------------------------------------- Read an entry from a user's environment
Line 2186  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 2219  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 2739  sub userlog_query { Line 2780  sub userlog_query {
   
 sub plaintext {  sub plaintext {
     my $short=shift;      my $short=shift;
     return $prp{$short};      return &mt($prp{$short});
 }  }
   
 # ----------------------------------------------------------------- Assign Role  # ----------------------------------------------------------------- Assign Role
Line 3267  sub condval { Line 3308  sub condval {
 sub devalidatecourseresdata {  sub devalidatecourseresdata {
     my ($coursenum,$coursedomain)=@_;      my ($coursenum,$coursedomain)=@_;
     my $hashid=$coursenum.':'.$coursedomain;      my $hashid=$coursenum.':'.$coursedomain;
     delete $courseresdatacache{$hashid.'.time'};      &devalidate_cache(\%courseresdatacache,$hashid);
 }  }
   
 # --------------------------------------------------- Course Resourcedata Query  # --------------------------------------------------- Course Resourcedata Query
Line 3276  sub courseresdata { Line 3317  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 $dodump=0;      my ($result,$cached)=&is_cached(\%courseresdatacache,$hashid);
     if (!defined($courseresdatacache{$hashid.'.time'})) {      unless (defined($cached)) {
  $dodump=1;  
     } else {  
  if (time-$courseresdatacache{$hashid.'.time'}>300) { $dodump=1; }  
     }  
     if ($dodump) {  
  my %dumpreply=&dump('resourcedata',$coursedomain,$coursenum);   my %dumpreply=&dump('resourcedata',$coursedomain,$coursenum);
    $result=\%dumpreply;
  my ($tmp) = keys(%dumpreply);   my ($tmp) = keys(%dumpreply);
  if ($tmp !~ /^(con_lost|error|no_such_host)/i) {   if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
     $courseresdatacache{$hashid.'.time'}=time;      &do_cache(\%courseresdatacache,$hashid,$result);
     $courseresdatacache{$hashid}=\%dumpreply;  
  } elsif ($tmp =~ /^(con_lost|no_such_host)/) {   } elsif ($tmp =~ /^(con_lost|no_such_host)/) {
     return $tmp;      return $tmp;
    } elsif ($tmp =~ /^(error)/) {
       $result=undef;
       &do_cache(\%courseresdatacache,$hashid,$result);
  }   }
     }      }
     foreach my $item (@which) {      foreach my $item (@which) {
  if (defined($courseresdatacache{$hashid}->{$item})) {   if (defined($result->{$item})) {
     return $courseresdatacache{$hashid}->{$item};      return $result->{$item};
  }   }
     }      }
     return undef;      return undef;
Line 3462  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 3590  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;
Line 3783  sub gettitle { Line 3829  sub gettitle {
  unless ($urlsymb) { $urlsymb=$ENV{'request.filename'}; }   unless ($urlsymb) { $urlsymb=$ENV{'request.filename'}; }
         return &metadata($urlsymb,'title');           return &metadata($urlsymb,'title'); 
     }      }
     if ($titlecache{$symb}) {      my ($result,$cached)=&is_cached(\%titlecache,$symb,600);
  if (time < ($titlecache{$symb}[1] + 600)) {      if (defined($cached)) { return $result; }
     return $titlecache{$symb}[0];  
  } else {  
     delete($titlecache{$symb});  
  }  
     }  
     my ($map,$resid,$url)=&decode_symb($symb);      my ($map,$resid,$url)=&decode_symb($symb);
     my $title='';      my $title='';
     my %bighash;      my %bighash;
Line 3801  sub gettitle { Line 3842  sub gettitle {
     }      }
     $title=~s/\&colon\;/\:/gs;      $title=~s/\&colon\;/\:/gs;
     if ($title) {      if ($title) {
         $titlecache{$symb}=[$title,time];          return &do_cache(\%titlecache,$symb,$title);
         return $title;  
     } else {      } else {
  return &metadata($urlsymb,'title');   return &metadata($urlsymb,'title');
     }      }
Line 4195  sub unescape { Line 4235  sub unescape {
     return $str;      return $str;
 }  }
   
   sub mod_perl_version {
       if (defined($perlvar{'MODPERL2'})) {
    return 2;
       }
       return 1;
   }
 # ================================================================ Main Program  # ================================================================ Main Program
   
 sub goodbye {  sub goodbye {

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


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