[LON-CAPA-cvs] cvs: loncom / lond

foxr lon-capa-cvs@mail.lon-capa.org
Tue, 10 Aug 2004 11:30:24 -0000


foxr		Tue Aug 10 07:30:24 2004 EDT

  Modified files:              
    /loncom	lond 
  Log:
  Complete and debug handlerization of fetchuserfile, removeuserfile.
  
  
  
Index: loncom/lond
diff -u loncom/lond:1.225 loncom/lond:1.226
--- loncom/lond:1.225	Mon Aug  9 06:34:18 2004
+++ loncom/lond	Tue Aug 10 07:30:24 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.225 2004/08/09 10:34:18 foxr Exp $
+# $Id: lond,v 1.226 2004/08/10 11:30:24 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -57,7 +57,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.225 $'; #' stupid emacs
+my $VERSION='$Revision: 1.226 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -162,8 +162,6 @@
     $Failures     = 0;
 }
 
-
-
 #------------------------------------------------------------------------
 #
 #   LocalConnection
@@ -372,7 +370,6 @@
 #                     - This allows dynamic changes to the manager table
 #                       without the need to signal to the lond.
 #
-
 sub ReadManagerTable {
 
     #   Clean out the old table first..
@@ -1743,7 +1740,8 @@
 &register_handler("update", \&update_resource_handler, 0 ,1, 0);
 
 #
-#   Fetch a user file from a remote server:
+#   Fetch a user file from a remote server to the user's home directory
+#   userfiles subdir.
 # Parameters:
 #    $cmd      - The command that got us here.
 #    $tail     - Tail of the command (remaining parameters).
@@ -1798,6 +1796,49 @@
 }
 &register_handler("fetchuserfile", \&fetch_user_file_handler, 0, 1, 0);
 
+#
+#   Remove a file from a user's home directory userfiles subdirectory.
+# Parameters:
+#    cmd   - the Lond request keyword that got us here.
+#    tail  - the part of the command past the keyword.
+#    client- File descriptor connected with the client.
+#
+# Returns:
+#    1    - Continue processing.
+
+sub remove_user_file_handler {
+    my ($cmd, $tail, $client) = @_;
+
+    my ($fname) = split(/:/, $tail); # Get rid of any tailing :'s lonc may have sent.
+
+    my ($udom,$uname,$ufile) = ($fname =~ m|^([^/]+)/([^/]+)/(.+)$|);
+    &logthis("$udom - $uname - $ufile");
+    if ($ufile =~m|/\.\./|) {
+	# any files paths with /../ in them refuse 
+	# to deal with
+	&Failure($client, "refused\n", "$cmd:$tail");
+    } else {
+	my $udir = &propath($udom,$uname);
+	if (-e $udir) {
+	    my $file=$udir.'/userfiles/'.$ufile;
+	    if (-e $file) {
+		unlink($file);
+		if (-e $file) {
+		    &Failure($client, "failed\n", "$cmd:$tail");
+		} else {
+		    &Reply($client, "ok\n", "$cmd:$tail");
+		}
+	    } else {
+		&Failure($client, "not_found\n", "$cmd:$tail");
+	    }
+	} else {
+	    &Failure($client, "not_home\n", "$cmd:$tail");
+	}
+    }
+    return 1;
+}
+&register_handler("removeuserfile", \&remove_user_file_handler, 0,1,0);
+
 #---------------------------------------------------------------
 #
 #   Getting, decoding and dispatching requests:
@@ -1808,11 +1849,11 @@
 #   Gets a Request message from the client.  The transaction
 #   is defined as a 'line' of text.  We remove the new line
 #   from the text line.  
-#   
+#
 sub get_request {
     my $input = <$client>;
     chomp($input);
-j
+
     Debug("get_request: Request = $input\n");
 
     &status('Processing '.$clientname.':'.$input);
@@ -1912,39 +1953,10 @@
 #------------------- Commands not yet in spearate handlers. --------------
 
 
-# --------------------------------------------------------- remove a user file 
-   if ($userinput =~ /^removeuserfile/) { # Client clear or enc.
-	if(isClient) {
-	    my ($cmd,$fname)=split(/:/,$userinput);
-	    my ($udom,$uname,$ufile) = ($fname =~ m|^([^/]+)/([^/]+)/(.+)$|);
-	    &logthis("$udom - $uname - $ufile");
-	    if ($ufile =~m|/\.\./|) {
-		# any files paths with /../ in them refuse 
-		# to deal with
-		print $client "refused\n";
-	    } else {
-		my $udir=propath($udom,$uname);
-		if (-e $udir) {
-		    my $file=$udir.'/userfiles/'.$ufile;
-		    if (-e $file) {
-			unlink($file);
-			if (-e $file) {
-			    print $client "failed\n";
-			} else {
-			    print $client "ok\n";
-			}
-		    } else {
-			print $client "not_found\n";
-		    }
-		} else {
-		    print $client "not_home\n";
-		}
-	    }
-	} else {
-	    Reply($client, "refused\n", $userinput);
-	}
+
 # ------------------------------------------ authenticate access to a user file
-    } elsif ($userinput =~ /^tokenauthuserfile/) { # Client only
+
+    if ($userinput =~ /^tokenauthuserfile/) { # Client only
 	if(isClient) {
 	    my ($cmd,$fname,$session)=split(/:/,$userinput);
 	    chomp($session);
@@ -3104,7 +3116,6 @@
    
     $Dispatcher{$request_name} = \@entry;
    
-   
 }
 
 
@@ -3151,7 +3162,6 @@
     $server->close();
     die($error);
 }
-
 sub timeout {
     &status("Handling Timeout");
     &logthis("<font color='red'>CRITICAL: TIME OUT ".$$."</font>");
@@ -3159,6 +3169,7 @@
 }
 # -------------------------------- Set signal handlers to record abnormal exits
 
+
 $SIG{'QUIT'}=\&catchexception;
 $SIG{__DIE__}=\&catchexception;