[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 30 Jun 2004 12:33:48 -0000


albertel		Wed Jun 30 08:33:48 2004 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - should be able to talk to 1.1 machines from a 1.2 machine
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.516 loncom/lonnet/perl/lonnet.pm:1.517
--- loncom/lonnet/perl/lonnet.pm:1.516	Tue Jun 29 10:56:32 2004
+++ loncom/lonnet/perl/lonnet.pm	Wed Jun 30 08:33:47 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.516 2004/06/29 14:56:32 raeburn Exp $
+# $Id: lonnet.pm,v 1.517 2004/06/30 12:33:47 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4879,6 +4879,14 @@
 	    if ($rtncode eq '404') {
 		unlink($localfile);
 	    }
+	    #my $ua=new LWP::UserAgent;
+	    #my $request=new HTTP::Request('GET',&tokenwrapper($file));
+	    #my $response=$ua->request($request);
+	    #if ($response->is_success()) {
+	#	return $response->content;
+	#    } else {
+	#	return -1;
+	#    }
 	    return -1;
 	}
 	if ($info < $fileinfo[9]) {
@@ -4891,8 +4899,16 @@
 	}
     } else {
 	$lwpresp = &getuploaded('GET',$file,$cdom,$cnum,\$info,\$rtncode);
+	&logthis("return is $lwpresp");
 	if ($lwpresp ne 'ok') {
-	    return -1;
+	    my $ua=new LWP::UserAgent;
+	    my $request=new HTTP::Request('GET',&tokenwrapper($file));
+	    my $response=$ua->request($request);
+	    if ($response->is_success()) {
+		return $response->content;
+	    } else {
+		return -1;
+	    }
 	}
 	my @parts = ($cdom,$cnum); 
 	if ($filename =~ m|^(.+)/[^/]+$|) {
@@ -4914,6 +4930,22 @@
     return $info;
 }
 
+sub tokenwrapper {
+    my $uri=shift;
+    $uri=~s/^http\:\/\/([^\/]+)//;
+    $uri=~s/^\///;
+    $ENV{'user.environment'}=~/\/([^\/]+)\.id/;
+    my $token=$1;
+    if ($uri=~/^uploaded\/([^\/]+)\/([^\/]+)\/([^\/]+)(\?\.*)*$/) {
+        &appenv('userfile.'.$1.'/'.$2.'/'.$3 => $ENV{'request.course.id'});
+        return 'http://'.$hostname{ &homeserver($2,$1)}.'/'.$uri.
+               (($uri=~/\?/)?'&':'?').'token='.$token.
+                               '&tokenissued='.$perlvar{'lonHostID'};
+    } else {
+        return '/adm/notfound.html';
+    }
+}
+
 sub getuploaded {
     my ($reqtype,$uri,$cdom,$cnum,$info,$rtncode) = @_;
     $uri=~s/^\///;