Diff for /loncom/lonnet/perl/lonnet.pm between versions 1.1425 and 1.1429

version 1.1425, 2020/09/28 13:08:57 version 1.1429, 2020/10/15 19:17:40
Line 8290  sub allowed { Line 8290  sub allowed {
                         } elsif ($noblockcheck) {                          } elsif ($noblockcheck) {
                             $thisallowed='F';                              $thisallowed='F';
                         } else {                          } else {
                             my @blockers = &has_comm_blocking($priv,$symb,$refuri,$ignorecache);                              my @blockers = &has_comm_blocking($priv,'',$refuri,'',1);
                             if (@blockers > 0) {                              if (@blockers > 0) {
                                 $thisallowed = 'B';                                  $thisallowed = 'B';
                             } else {                              } else {
Line 8408  sub allowed { Line 8408  sub allowed {
                       } elsif ($noblockcheck) {                        } elsif ($noblockcheck) {
                           $thisallowed.=$value;                            $thisallowed.=$value;
                       } else {                        } else {
                           my @blockers = &has_comm_blocking($priv,'',$refuri,$ignorecache);                            my @blockers = &has_comm_blocking($priv,'',$refuri,'',1);
                           if (@blockers > 0) {                            if (@blockers > 0) {
                               $thisallowed = 'B';                                $thisallowed = 'B';
                           } else {                            } else {
Line 8665  sub constructaccess { Line 8665  sub constructaccess {
 my $cacheduser='';  my $cacheduser='';
 # Course for which data are being temporarily cached.  # Course for which data are being temporarily cached.
 my $cachedcid='';  my $cachedcid='';
 # List of blocks passed to &get_commblock_resources();  
 my $cachedblocks='';  
 # Cached blockers for this user (a hash of blocking items).   # Cached blockers for this user (a hash of blocking items). 
 my %cachedblockers=();  my %cachedblockers=();
 # When the data were last cached.  # When the data were last cached.
 my $cachedlast='';  my $cachedlast='';
   
 sub load_all_blockers {  sub load_all_blockers {
     my ($uname,$udom,$blocks)=@_;      my ($uname,$udom)=@_;
     if (($uname ne '') && ($udom ne '')) {       if (($uname ne '') && ($udom ne '')) { 
         if (($cacheduser eq $uname.':'.$udom) &&          if (($cacheduser eq $uname.':'.$udom) &&
             ($cachedcid eq $env{'request.course.id'}) &&              ($cachedcid eq $env{'request.course.id'}) &&
             (abs($cachedlast-time)<5) &&              (abs($cachedlast-time)<5)) {
             (((ref($blocks) eq 'HASH') &&  
               ($cachedblocks eq join(',',sort(keys(%{$blocks}))))) ||  
              (!ref($blocks) && $cachedblocks eq ''))) {  
             return;              return;
         }          }
     }      }
     $cachedlast=time;      $cachedlast=time;
     $cacheduser=$uname.':'.$udom;      $cacheduser=$uname.':'.$udom;
     $cachedcid=$env{'request.course.id'};      $cachedcid=$env{'request.course.id'};
     %cachedblockers = &get_commblock_resources($blocks);      %cachedblockers = &get_commblock_resources();
     if ((ref($blocks) eq 'HASH') && (keys(%{$blocks}) > 0)) {  
         $cachedblocks = join(',',sort(keys(%{$blocks})));  
     }  
     return;      return;
 }  }
   
Line 8771  sub get_commblock_resources { Line 8763  sub get_commblock_resources {
                             if ($mapsymb) {                              if ($mapsymb) {
                                 if (ref($navmap)) {                                  if (ref($navmap)) {
                                     my $mapres = $navmap->getBySymb($mapsymb);                                      my $mapres = $navmap->getBySymb($mapsymb);
                                     @to_test = $mapres->retrieveResources($mapres,undef,0,0,0,1);                                      if (ref($mapres)) {
                                     foreach my $res (@to_test) {                                          my $first = $mapres->map_start();
                                         my $symb = $res->symb();                                          my $finish = $mapres->map_finish();
                                         next if ($symb eq $mapsymb);                                          my $it = $navmap->getIterator($first,$finish,undef,0,0);
                                         if ($symb ne '') {                                          if (ref($it)) {
                                             @interval=&EXT("resource.0.interval",$symb);                                              my $res;
                                             if ($interval[1] eq 'map') {                                              while ($res = $it->next(undef,1)) {
                                                 last;                                                  next unless (ref($res));
                                                   my $symb = $res->symb();
                                                   next if (($symb eq $mapsymb) || ($symb eq ''));
                                                   @interval=&EXT("resource.0.interval",$symb);
                                                   if ($interval[1] eq 'map') {
                                                       if ($res->answerable()) {
                                                           push(@to_test,$res);
                                                           last;
                                                       }
                                                   }
                                             }                                              }
                                         }                                          }
                                     }                                      }
Line 8829  sub get_commblock_resources { Line 8830  sub get_commblock_resources {
 }  }
   
 sub has_comm_blocking {  sub has_comm_blocking {
     my ($priv,$symb,$uri,$nosymbcache,$blocked,$blocks) = @_;      my ($priv,$symb,$uri,$ignoresymbdb,$noenccheck,$blocked,$blocks) = @_;
     my @blockers;      my @blockers;
     return unless ($env{'request.course.id'});      return unless ($env{'request.course.id'});
     return unless ($priv eq 'bre');      return unless ($priv eq 'bre');
     return if ($env{'user.priv.'.$env{'request.role'}} =~/evb\&([^\:]*)/);      return if ($env{'user.priv.'.$env{'request.role'}} =~/evb\&([^\:]*)/);
     return if ($env{'request.state'} eq 'construct');      return if ($env{'request.state'} eq 'construct');
     &load_all_blockers($env{'user.name'},$env{'user.domain'},$blocks);      my %blockinfo;
     return unless (keys(%cachedblockers) > 0);      if (ref($blocks) eq 'HASH') {
           %blockinfo = &get_commblock_resources($blocks);
       } else {
           &load_all_blockers($env{'user.name'},$env{'user.domain'});
           %blockinfo = %cachedblockers;
       }
       return unless (keys(%blockinfo) > 0);
     my (%possibles,@symbs);      my (%possibles,@symbs);
     if (!$symb) {      if (!$symb) {
         $symb = &symbread($uri,1,1,'',\%possibles,$nosymbcache);          $symb = &symbread($uri,1,1,1,\%possibles,$ignoresymbdb,$noenccheck);
     }      }
     if ($symb) {      if ($symb) {
         @symbs = ($symb);          @symbs = ($symb);
Line 8850  sub has_comm_blocking { Line 8857  sub has_comm_blocking {
     foreach my $symb (@symbs) {      foreach my $symb (@symbs) {
         last if ($noblock);          last if ($noblock);
         my ($map,$resid,$resurl)=&decode_symb($symb);          my ($map,$resid,$resurl)=&decode_symb($symb);
         foreach my $block (keys(%cachedblockers)) {          foreach my $block (keys(%blockinfo)) {
             if ($block =~ /^firstaccess____(.+)$/) {              if ($block =~ /^firstaccess____(.+)$/) {
                 my $item = $1;                  my $item = $1;
                 unless ($blocked) {                  unless ($blocked) {
Line 8860  sub has_comm_blocking { Line 8867  sub has_comm_blocking {
                     }                      }
                 }                  }
             }              }
             if (ref($cachedblockers{$block}) eq 'HASH') {              if (ref($blockinfo{$block}) eq 'HASH') {
                 if (ref($cachedblockers{$block}{'resources'}) eq 'HASH') {                  if (ref($blockinfo{$block}{'resources'}) eq 'HASH') {
                     if ($cachedblockers{$block}{'resources'}{$symb}) {                      if ($blockinfo{$block}{'resources'}{$symb}) {
                         unless (grep(/^\Q$block\E$/,@blockers)) {                          unless (grep(/^\Q$block\E$/,@blockers)) {
                             push(@blockers,$block);                              push(@blockers,$block);
                         }                          }
                     }                      }
                 }                  }
                 if (ref($cachedblockers{$block}{'maps'}) eq 'HASH') {                  if (ref($blockinfo{$block}{'maps'}) eq 'HASH') {
                     if ($cachedblockers{$block}{'maps'}{$map}) {                      if ($blockinfo{$block}{'maps'}{$map}) {
                         unless (grep(/^\Q$block\E$/,@blockers)) {                          unless (grep(/^\Q$block\E$/,@blockers)) {
                             push(@blockers,$block);                              push(@blockers,$block);
                         }                          }
Line 13310  sub deversion { Line 13317  sub deversion {
   
 sub symbread {  sub symbread {
     my ($thisfn,$donotrecurse,$ignorecachednull,$checkforblock,$possibles,      my ($thisfn,$donotrecurse,$ignorecachednull,$checkforblock,$possibles,
         $nocache)=@_;          $ignoresymbdb,$noenccheck)=@_;
     my $cache_str='request.symbread.cached.'.$thisfn;      my $cache_str='request.symbread.cached.'.$thisfn;
     if (defined($env{$cache_str}) && !$nocache) {      if (defined($env{$cache_str})) {
         unless (ref($possibles) eq 'HASH') {          unless (ref($possibles) eq 'HASH') {
             if ($ignorecachednull) {              if ($ignorecachednull) {
                 return $env{$cache_str} unless ($env{$cache_str} eq '');                  return $env{$cache_str} unless ($env{$cache_str} eq '');
Line 13324  sub symbread { Line 13331  sub symbread {
 # no filename provided? try from environment  # no filename provided? try from environment
     unless ($thisfn) {      unless ($thisfn) {
         if ($env{'request.symb'}) {          if ($env{'request.symb'}) {
             if ($nocache) {              return $env{$cache_str}=&symbclean($env{'request.symb'});
                 return &symbclean($env{'request.symb'});  
             } else {  
                 return $env{$cache_str}=&symbclean($env{'request.symb'});  
             }  
  }   }
  $thisfn=$env{'request.filename'};   $thisfn=$env{'request.filename'};
     }      }
Line 13336  sub symbread { Line 13339  sub symbread {
 # is that filename actually a symb? Verify, clean, and return  # is that filename actually a symb? Verify, clean, and return
     if ($thisfn=~/\_\_\_\d+\_\_\_(.*)$/) {      if ($thisfn=~/\_\_\_\d+\_\_\_(.*)$/) {
  if (&symbverify($thisfn,$1)) {   if (&symbverify($thisfn,$1)) {
             if ($nocache) {      return $env{$cache_str}=&symbclean($thisfn);
                 return &symbclean($thisfn);  
             } else {  
         return $env{$cache_str}=&symbclean($thisfn);  
             }  
  }   }
     }      }
     $thisfn=declutter($thisfn);      $thisfn=declutter($thisfn);
Line 13355  sub symbread { Line 13354  sub symbread {
  if ($targetfn =~ m|^adm/wrapper/(ext/.*)|) {   if ($targetfn =~ m|^adm/wrapper/(ext/.*)|) {
     $targetfn=$1;      $targetfn=$1;
  }   }
         unless ($nocache) {          unless ($ignoresymbdb) {
             if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',              if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
                           &GDBM_READER(),0640)) {                            &GDBM_READER(),0640)) {
         $syval=$hash{$targetfn};          $syval=$hash{$targetfn};
                 untie(%hash);                  untie(%hash);
             }              }
             if ($syval) {              if ($syval && $checkforblock) {
                 my @blockers = &has_comm_blocking('bre',$syval,$thisfn,$nocache);                  my @blockers = &has_comm_blocking('bre',$syval,$thisfn,$ignoresymbdb,$noenccheck);
                 if (@blockers) {                  if (@blockers) {
                     $syval='';                      $syval='';
                 }                  }
Line 13405  sub symbread { Line 13404  sub symbread {
                      }                       }
                      if ($checkforblock) {                       if ($checkforblock) {
                          unless ($bighash{'randomout_'.$ids} || $env{'request.role.adv'}) {                           unless ($bighash{'randomout_'.$ids} || $env{'request.role.adv'}) {
                              my @blockers = &has_comm_blocking('bre',$syval,$bighash{'src_'.$ids});                               my @blockers = &has_comm_blocking('bre',$syval,$bighash{'src_'.$ids},'',$noenccheck);
                              if (@blockers) {                               if (@blockers) {
                                  $syval = '';                                   $syval = '';
                                  untie(%bighash);                                   untie(%bighash);
                                  return '' if ($nocache);  
                                  return $env{$cache_str}='';                                   return $env{$cache_str}='';
                              }                               }
                          }                           }
Line 13431  sub symbread { Line 13429  sub symbread {
                                  my $poss_syval=&encode_symb($bighash{'map_id_'.$mapid},                                   my $poss_syval=&encode_symb($bighash{'map_id_'.$mapid},
              $resid,$thisfn);               $resid,$thisfn);
                                  next if ($bighash{'randomout_'.$id} && !$env{'request.role.adv'});                                   next if ($bighash{'randomout_'.$id} && !$env{'request.role.adv'});
                                  next unless ($bighash{'encrypted_'.$id} eq $env{'request.enc'});                                   next unless (($noenccheck) || ($bighash{'encrypted_'.$id} eq $env{'request.enc'}));
                                  if ($checkforblock) {                                   if ($checkforblock) {
                                      my @blockers = &has_comm_blocking('bre',$poss_syval,$file);                                       my @blockers = &has_comm_blocking('bre',$poss_syval,$file,'',$noenccheck);
                                      if (@blockers > 0) {                                       if (@blockers > 0) {
                                          $syval = '';                                           $syval = '';
                                      } else {                                       } else {
Line 13461  sub symbread { Line 13459  sub symbread {
            }             }
         }          }
         if ($syval) {          if ($syval) {
             if ($nocache) {      return $env{$cache_str}=$syval;
                 return $syval;  
             } else {  
         return $env{$cache_str}=$syval;  
             }  
         }          }
     }      }
     &appenv({'request.ambiguous' => $thisfn});      &appenv({'request.ambiguous' => $thisfn});
     return '' if ($nocache);  
     return $env{$cache_str}='';      return $env{$cache_str}='';
 }  }
   

Removed from v.1.1425  
changed lines
  Added in v.1.1429


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