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

version 1.413, 2003/09/16 17:54:50 version 1.422, 2003/09/25 19:47:13
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 2739  sub userlog_query { Line 2773  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 3301  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 3310  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 3494  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 3594  sub metadata { Line 3633  sub metadata {
     $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 =~ /^~/)) {
  return '';   return '';
     }      }
     my $filename=$uri;      my $filename=$uri;
Line 3783  sub gettitle { Line 3822  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 3835  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 4228  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.422


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