[LON-CAPA-cvs] cvs: loncom /auth lonacc.pm loncacc.pm /interface loncommon.pm /lonnet/perl lonnet.pm

www lon-capa-cvs@mail.lon-capa.org
Tue, 13 May 2003 00:52:47 -0000


This is a MIME encoded message

--www1052787167
Content-Type: text/plain

www		Mon May 12 20:52:47 2003 EDT

  Modified files:              
    /loncom/auth	lonacc.pm loncacc.pm 
    /loncom/interface	loncommon.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  Consolidate functions from access control handlers in order to eventually
  add them also to lonuploadedacc.pm - preparation for running uploaded
  problems.
  
  
--www1052787167
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20030512205247.txt"

Index: loncom/auth/lonacc.pm
diff -u loncom/auth/lonacc.pm:1.45 loncom/auth/lonacc.pm:1.46
--- loncom/auth/lonacc.pm:1.45	Tue May  6 17:45:25 2003
+++ loncom/auth/lonacc.pm	Mon May 12 20:52:46 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Cookie Based Access Handler
 #
-# $Id: lonacc.pm,v 1.45 2003/05/06 21:45:25 albertel Exp $
+# $Id: lonacc.pm,v 1.46 2003/05/13 00:52:46 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -59,22 +59,12 @@
         my $lonidsdir=$r->dir_config('lonIDsDir');
         if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
 
-# ------------------------------------------- Transfer profile into environment
+# ------------------------------------------------------ Initialize Environment
+
+            &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
+
+# -------------------------------------------------------------- Resource State
 
-            my @profile;
-	    {
-             my $idf=Apache::File->new("$lonidsdir/$handle.id");
-             flock($idf,LOCK_SH);
-             @profile=<$idf>;
-             $idf->close();
-	    }
-            my $envi;
-            for ($envi=0;$envi<=$#profile;$envi++) {
-		chomp($profile[$envi]);
-		my ($envname,$envvalue)=split(/=/,$profile[$envi]);
-                $ENV{$envname} = $envvalue;
-            }
-            $ENV{'user.environment'} = "$lonidsdir/$handle.id";
             if ($requrl=~/^\/res\//) {
                $ENV{'request.state'} = "published";
 	    } else {
@@ -84,72 +74,7 @@
 
 # -------------------------------------------------------- Load POST parameters
 
-
-           
-        my $buffer;
-
-        $r->read($buffer,$r->header_in('Content-length'),0);
-	unless ($buffer=~/^(\-+\w+)\s+Content\-Disposition\:\s*form\-data/si) {
-            my @pairs=split(/&/,$buffer);
-            my $pair;
-            foreach $pair (@pairs) {
-               my ($name,$value) = split(/=/,$pair);
-               $value =~ tr/+/ /;
-               $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
-               $name  =~ tr/+/ /;
-               $name  =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
-	       &Apache::loncommon::add_to_env("form.$name",$value);
-            }
-        } else {
-	    my $contentsep=$1;
-            my @lines = split (/\n/,$buffer);
-            my $name='';
-            my $value='';
-            my $fname='';
-            my $fmime='';
-            my $i;
-            for ($i=0;$i<=$#lines;$i++) {
-		if ($lines[$i]=~/^$contentsep/) {
-		    if ($name) {
-                        chomp($value);
-			if ($fname) {
-			    $ENV{"form.$name.filename"}=$fname;
-                            $ENV{"form.$name.mimetype"}=$fmime;
-                        } else {
-                            $value=~s/\s+$//s;
-                        }
-			&Apache::loncommon::add_to_env("form.$name",$value);
-                    }
-                    if ($i<$#lines) {
-			$i++;
-                        $lines[$i]=~
-		 /Content\-Disposition\:\s*form\-data\;\s*name\=\"([^\"]+)\"/i;
-                        $name=$1;
-                        $value='';
-                        if ($lines[$i]=~/filename\=\"([^\"]+)\"/i) {
-			   $fname=$1;
-                           if 
-                            ($lines[$i+1]=~/Content\-Type\:\s*([\w\-\/]+)/i) {
-			      $fmime=$1;
-                              $i++;
-			   } else {
-                              $fmime='';
-                           }
-                        } else {
-			    $fname='';
-                            $fmime='';
-                        }
-                        $i++;
-                    }
-                } else {
-		    $value.=$lines[$i]."\n";
-                }
-            }
-	}
-	    $ENV{'request.method'}=$ENV{'REQUEST_METHOD'};
-            $r->method_number(M_GET);
-	    $r->method('GET');
-            $r->headers_in->unset('Content-length');
+	    &Apache::loncommon::get_posted_cgi($r);
 
 # ---------------------------------------------------------------- Check access
 
Index: loncom/auth/loncacc.pm
diff -u loncom/auth/loncacc.pm:1.27 loncom/auth/loncacc.pm:1.28
--- loncom/auth/loncacc.pm:1.27	Tue May  6 17:45:25 2003
+++ loncom/auth/loncacc.pm	Mon May 12 20:52:46 2003
@@ -2,7 +2,7 @@
 # Cookie Based Access Handler for Construction Area
 # (lonacc: 5/21/99,5/22,5/29,5/31 Gerd Kortemeyer)
 #
-# $Id: loncacc.pm,v 1.27 2003/05/06 21:45:25 albertel Exp $
+# $Id: loncacc.pm,v 1.28 2003/05/13 00:52:46 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -78,20 +78,13 @@
         $handle=~s/\W//g;
         my $lonidsdir=$r->dir_config('lonIDsDir');
         if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
-            my @profile;
-	    {
-             my $idf=Apache::File->new("$lonidsdir/$handle.id");
-             flock($idf,LOCK_SH);
-             @profile=<$idf>;
-             $idf->close();
-	    }
-            my $envi;
-            for ($envi=0;$envi<=$#profile;$envi++) {
-		chomp($profile[$envi]);
-		my ($envname,$envvalue)=split(/=/,$profile[$envi]);
-                $ENV{$envname} = $envvalue;
-            }
-            $ENV{'user.environment'} = "$lonidsdir/$handle.id";
+
+# ------------------------------------------------------ Initialize Environment
+
+            &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
+
+# -------------------------------------------------------------- Resource State
+
             $ENV{'request.state'}    = "construct";
             $ENV{'request.filename'} = $r->filename;
 
@@ -111,72 +104,7 @@
 
 # -------------------------------------------------------- Load POST parameters
 
-
-        my $buffer;
-
-        $r->read($buffer,$r->header_in('Content-length'),0);
-
-	unless ($buffer=~/^(\-+\w+)\s+Content\-Disposition\:\s*form\-data/si) {
-            my @pairs=split(/&/,$buffer);
-            my $pair;
-            foreach $pair (@pairs) {
-               my ($name,$value) = split(/=/,$pair);
-               $value =~ tr/+/ /;
-               $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
-               $name  =~ tr/+/ /;
-               $name  =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
-	       &Apache::loncommon::add_to_env("form.$name",$value);
-            } 
-        } else {
-	    my $contentsep=$1;
-            my @lines = split (/\n/,$buffer);
-            my $name='';
-            my $value='';
-            my $fname='';
-            my $fmime='';
-            my $i;
-            for ($i=0;$i<=$#lines;$i++) {
-		if ($lines[$i]=~/^$contentsep/) {
-		    if ($name) {
-                        chomp($value);
-			if ($fname) {
-			    $ENV{"form.$name.filename"}=$fname;
-                            $ENV{"form.$name.mimetype"}=$fmime;
-                        } else {
-                            $value=~s/\s+$//s;
-                        }
-			&Apache::loncommon::add_to_env("form.$name",$value);
-                    }
-                    if ($i<$#lines) {
-			$i++;
-                        $lines[$i]=~
-		 /Content\-Disposition\:\s*form\-data\;\s*name\=\"([^\"]+)\"/i;
-                        $name=$1;
-                        $value='';
-                        if ($lines[$i]=~/filename\=\"([^\"]+)\"/i) {
-			   $fname=$1;
-                           if 
-                            ($lines[$i+1]=~/Content\-Type\:\s*([\w\-\/]+)/i) {
-			      $fmime=$1;
-                              $i++;
-			   } else {
-                              $fmime='';
-                           }
-                        } else {
-			    $fname='';
-                            $fmime='';
-                        }
-                        $i++;
-                    }
-                } else {
-		    $value.=$lines[$i]."\n";
-                }
-            }
-	}
-            $ENV{'request.method'}=$ENV{'REQUEST_METHOD'};
-            $r->method_number(M_GET);
-	    $r->method('GET');
-            $r->headers_in->unset('Content-length');
+	    &Apache::loncommon::get_posted_cgi($r);
 
             return OK; 
         } else { 
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.98 loncom/interface/loncommon.pm:1.99
--- loncom/interface/loncommon.pm:1.98	Sun May  4 17:20:17 2003
+++ loncom/interface/loncommon.pm	Mon May 12 20:52:46 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.98 2003/05/04 21:20:17 www Exp $
+# $Id: loncommon.pm,v 1.99 2003/05/13 00:52:46 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -79,7 +79,7 @@
 use Apache::lonnet();
 use GDBM_File;
 use POSIX qw(strftime mktime);
-use Apache::Constants qw(:common);
+use Apache::Constants qw(:common :http :methods);
 use Apache::lonmsg();
 use Apache::lonmenu();
 my $readit;
@@ -1785,6 +1785,78 @@
 </table><br>
 ENDBODY
 }
+
+###############################################
+
+sub get_posted_cgi {
+    my $r=shift;
+
+    my $buffer;
+    
+    $r->read($buffer,$r->header_in('Content-length'),0);
+    unless ($buffer=~/^(\-+\w+)\s+Content\-Disposition\:\s*form\-data/si) {
+	my @pairs=split(/&/,$buffer);
+	my $pair;
+	foreach $pair (@pairs) {
+	    my ($name,$value) = split(/=/,$pair);
+	    $value =~ tr/+/ /;
+	    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
+	    $name  =~ tr/+/ /;
+	    $name  =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
+	    &add_to_env("form.$name",$value);
+	}
+    } else {
+	my $contentsep=$1;
+	my @lines = split (/\n/,$buffer);
+	my $name='';
+	my $value='';
+	my $fname='';
+	my $fmime='';
+	my $i;
+	for ($i=0;$i<=$#lines;$i++) {
+	    if ($lines[$i]=~/^$contentsep/) {
+		if ($name) {
+		    chomp($value);
+		    if ($fname) {
+			$ENV{"form.$name.filename"}=$fname;
+			$ENV{"form.$name.mimetype"}=$fmime;
+		    } else {
+			$value=~s/\s+$//s;
+		    }
+		    &add_to_env("form.$name",$value);
+		}
+		if ($i<$#lines) {
+		    $i++;
+		    $lines[$i]=~
+		/Content\-Disposition\:\s*form\-data\;\s*name\=\"([^\"]+)\"/i;
+		    $name=$1;
+		    $value='';
+		    if ($lines[$i]=~/filename\=\"([^\"]+)\"/i) {
+			$fname=$1;
+			if 
+                            ($lines[$i+1]=~/Content\-Type\:\s*([\w\-\/]+)/i) {
+				$fmime=$1;
+				$i++;
+			    } else {
+				$fmime='';
+			    }
+		    } else {
+			$fname='';
+			$fmime='';
+		    }
+		    $i++;
+		}
+	    } else {
+		$value.=$lines[$i]."\n";
+	    }
+	}
+    }
+    $ENV{'request.method'}=$ENV{'REQUEST_METHOD'};
+    $r->method_number(M_GET);
+    $r->method('GET');
+    $r->headers_in->unset('Content-length');
+}
+
 ###############################################
 
 sub get_unprocessed_cgi {
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.373 loncom/lonnet/perl/lonnet.pm:1.374
--- loncom/lonnet/perl/lonnet.pm:1.373	Sat May 10 19:00:39 2003
+++ loncom/lonnet/perl/lonnet.pm	Mon May 12 20:52:47 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.373 2003/05/10 23:00:39 www Exp $
+# $Id: lonnet.pm,v 1.374 2003/05/13 00:52:47 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -242,6 +242,26 @@
         }
     }
     return $answer;
+}
+ 
+# ------------------------------------------- Transfer profile into environment
+
+sub transfer_profile_to_env {
+    my ($lonidsdir,$handle)=@_;
+    my @profile;
+    {
+	my $idf=Apache::File->new("$lonidsdir/$handle.id");
+	flock($idf,LOCK_SH);
+	@profile=<$idf>;
+	$idf->close();
+    }
+    my $envi;
+    for ($envi=0;$envi<=$#profile;$envi++) {
+	chomp($profile[$envi]);
+	my ($envname,$envvalue)=split(/=/,$profile[$envi]);
+	$ENV{$envname} = $envvalue;
+    }
+    $ENV{'user.environment'} = "$lonidsdir/$handle.id";
 }
 
 # ---------------------------------------------------------- Append Environment

--www1052787167--