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

foxr lon-capa-cvs@mail.lon-capa.org
Thu, 02 Sep 2004 09:27:58 -0000


foxr		Thu Sep  2 05:27:58 2004 EDT

  Modified files:              
    /loncom	lond 
  Log:
  Handlerize the following requests:
  - setannounce - set the node announcement text.
  - getversion  - Get the daemon version.
  - sethost     - Select the virtual host managed by the daemon.
  - exit etc.   - Disconnect and exit the daemon.
  
  
  
Index: loncom/lond
diff -u loncom/lond:1.245 loncom/lond:1.246
--- loncom/lond:1.245	Sun Aug 29 00:12:18 2004
+++ loncom/lond	Thu Sep  2 05:27:58 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.245 2004/08/29 04:12:18 albertel Exp $
+# $Id: lond,v 1.246 2004/09/02 09:27:58 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -57,7 +57,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.245 $'; #' stupid emacs
+my $VERSION='$Revision: 1.246 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -3369,6 +3369,126 @@
 }
 &register_handler("tmpdel", \&tmp_del_handler, 0, 1, 0);
 #
+#   Processes the setannounce command.  This command
+#   creates a file named announce.txt in the top directory of
+#   the documentn root and sets its contents.  The announce.txt file is
+#   printed in its entirety at the LonCAPA login page.  Note:
+#   once the announcement.txt fileis created it cannot be deleted.
+#   However, setting the contents of the file to empty removes the
+#   announcement from the login page of loncapa so who cares.
+#
+# Parameters:
+#    $cmd          - The command that got us dispatched.
+#    $announcement - The text of the announcement.
+#    $client       - Socket open on the client process.
+# Retunrns:
+#   1             - Indicating request processing should continue
+# Side Effects:
+#   The file {DocRoot}/announcement.txt is created.
+#   A reply is sent to $client.
+#
+sub set_announce_handler {
+    my ($cmd, $announcement, $client) = @_;
+  
+    my $userinput    = "$cmd:$announcement";
+
+    chomp($announcement);
+    $announcement=&unescape($announcement);
+    if (my $store=IO::File->new('>'.$perlvar{'lonDocRoot'}.
+				'/announcement.txt')) {
+	print $store $announcement;
+	close $store;
+	&Reply($client, "ok\n", $userinput);
+    } else {
+	&Failure($client, "error: ".($!+0)."\n", $userinput);
+    }
+
+    return 1;
+}
+&register_handler("setannounce", \&set_announce_handler, 0, 1, 0);
+#
+#  Return the version of the daemon.  This can be used to determine
+#  the compatibility of cross version installations or, alternatively to
+#  simply know who's out of date and who isn't.  Note that the version
+#  is returned concatenated with the tail.
+# Parameters:
+#   $cmd        - the request that dispatched to us.
+#   $tail       - Tail of the request (client's version?).
+#   $client     - Socket open on the client.
+#Returns:
+#   1 - continue processing requests.
+# Side Effects:
+#   Replies with version to $client.
+sub get_version_handler {
+    my ($cmd, $tail, $client) = @_;
+
+    my $userinput  = $cmd.$tail;
+    
+    &Reply($client, &version($userinput)."\n", $userinput);
+
+
+    return 1;
+}
+&register_handler("version", \&get_version_handler, 0, 1, 0);
+#  Set the current host and domain.  This is used to support
+#  multihomed systems.  Each IP of the system, or even separate daemons
+#  on the same IP can be treated as handling a separate lonCAPA virtual
+#  machine.  This command selects the virtual lonCAPA.  The client always
+#  knows the right one since it is lonc and it is selecting the domain/system
+#  from the hosts.tab file.
+# Parameters:
+#    $cmd      - Command that dispatched us.
+#    $tail     - Tail of the command (domain/host requested).
+#    $socket   - Socket open on the client.
+#
+# Returns:
+#     1   - Indicates the program should continue to process requests.
+# Side-effects:
+#     The default domain/system context is modified for this daemon.
+#     a reply is sent to the client.
+#
+sub set_virtual_host_handler {
+    my ($cmd, $tail, $socket) = @_;
+  
+    my $userinput  ="$cmd:$tail";
+
+    &Reply($client, &sethost($userinput)."\n", $userinput);
+
+
+    return 1;
+}
+&register_handler("sethost", \&select_virtual_host_handler, 0, 1, 0);
+
+#  Process a request to exit:
+#   - "bye" is sent to the client.
+#   - The client socket is shutdown and closed.
+#   - We indicate to the caller that we should exit.
+# Formal Parameters:
+#   $cmd                - The command that got us here.
+#   $tail               - Tail of the command (empty).
+#   $client             - Socket open on the tail.
+# Returns:
+#   0      - Indicating the program should exit!!
+#
+sub exit_handler {
+    my ($cmd, $tail, $client) = @_;
+
+    my $userinput = "$cmd:$tail";
+
+    &logthis("Client $clientip ($clientname) hanging up: $userinput");
+    &Reply($client, "bye\n", $userinput);
+    $client->shutdown(2);        # shutdown the socket forcibly.
+    $client->close();
+
+    return 0;
+}
+&register_handler("exit", \&exit_handler, 0,,1);
+&register_handler("init", \&exit_handler, 0,,1);
+&register_handler("quit", \&exit_handler, 0,,1);
+
+
+#
+#
 #
 #
 #
@@ -3485,52 +3605,8 @@
 
 #------------------- Commands not yet in spearate handlers. --------------
 
-
-
-# ----------------------------------------------------------------- setannounce
-    if ($userinput =~ /^setannounce/) {
-	if (isClient) {
-	    my ($cmd,$announcement)=split(/:/,$userinput);
-	    chomp($announcement);
-	    $announcement=&unescape($announcement);
-	    if (my $store=IO::File->new('>'.$perlvar{'lonDocRoot'}.
-					'/announcement.txt')) {
-		print $store $announcement;
-		close $store;
-		print $client "ok\n";
-	    } else {
-		print $client "error: ".($!+0)."\n";
-	    }
-	} else {
-	    Reply($client, "refused\n", $userinput);
-	    
-	}
-# ------------------------------------------------------------------ Hanging up
-    } elsif (($userinput =~ /^exit/) ||
-	     ($userinput =~ /^init/)) { # no restrictions.
-	&logthis(
-		 "Client $clientip ($clientname) hanging up: $userinput");
-	print $client "bye\n";
-	$client->shutdown(2);        # shutdown the socket forcibly.
-	$client->close();
-	return 0;
-	
-# ---------------------------------- set current host/domain
-    } elsif ($userinput =~ /^sethost/) {
-	if (isClient) {
-	    print $client &sethost($userinput)."\n";
-	} else {
-	    print $client "refused\n";
-	}
-#---------------------------------- request file (?) version.
-    } elsif ($userinput =~/^version/) {
-	if (isClient) {
-	    print $client &version($userinput)."\n";
-	} else {
-	    print $client "refused\n";
-	}
 #------------------------------- is auto-enrollment enabled?
-    } elsif ($userinput =~/^autorun/) {
+    if ($userinput =~/^autorun/) {
 	if (isClient) {
 	    my ($cmd,$cdom) = split(/:/,$userinput);
 	    my $outcome = &localenroll::run($cdom);