[LON-CAPA-cvs] cvs: loncom(Refactoring) / lond

foxr lon-capa-cvs@mail.lon-capa.org
Tue, 27 Apr 2004 11:30:28 -0000


foxr		Tue Apr 27 07:30:28 2004 EDT

  Modified files:              (Branch: Refactoring)
    /loncom	lond 
  Log:
  - Fix mis-spelling of unsub in registration.]
  - Fix(?) problem with unsub not being able to unsubscribe when resource.ip was not present
    but subscriptions were there in the subscription file.
   (make the subscription file the authoritative information source).
  - Add a few little touches to some functions with only one parameter to make interactive
    debugging via telnet easier (telnet terminates lines with \r which chomp won't chomp
    as near as I can tell... I have split even the final parameter from the line with /:/
    so the user can work around this with e.g. unsub:filename: and the filename won't be searched
    for with the \r present on the back end of it.).
  
  
  
Index: loncom/lond
diff -u loncom/lond:1.178.2.19 loncom/lond:1.178.2.20
--- loncom/lond:1.178.2.19	Mon Apr 26 06:37:47 2004
+++ loncom/lond	Tue Apr 27 07:30:28 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.178.2.19 2004/04/26 10:37:47 foxr Exp $
+# $Id: lond,v 1.178.2.20 2004/04/27 11:30:28 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -53,7 +53,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.178.2.19 $'; #' stupid emacs
+my $VERSION='$Revision: 1.178.2.20 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid;
 my $currentdomainid;
@@ -1028,7 +1028,9 @@
    
     my $userinput = "$cmd:$tail";
    
-    my $fname=$tail;
+    my $fname=split(/:/$tail);	# This allows interactive testing
+    chomp($fname);		# with telnet.
+
     my $ownership=ishome($fname);
     if ($ownership eq 'not_owner') {
 	if (-e $fname) {
@@ -1188,15 +1190,20 @@
     my $client   = shift;
     my $userinput= "$cmd:$tail";
     
-    my $fname = $tail;
+    my ($fname) = split(/:/,$tail); # This allows for interactive testing
+                                    # e.g. manual telnet and unsub:res:
+                                    # Otherwise the \r gets in the way. 
+    chomp($fname);
+    Debug("Unsubscribing $fname");
     if (-e $fname) {
-	Reply($client, &unsub($client,$fname,$clientip), $userinput);
+	Debug("Exists");
+	Reply($client, &unsub($fname,$clientip), $userinput);
     } else {
 	Failure($client, "not_found\n", $userinput);
     }
     return 1;
 }
-RegisterHandler("unusb", \&UnsubscribeHandler, 0, 1, 0);
+RegisterHandler("unsub", \&UnsubscribeHandler, 0, 1, 0);
 
 #   Subscribe to a resource
 #
@@ -3818,9 +3825,13 @@
 
 sub ishome {
     my $author=shift;
+    Debug("ishome: $author");
     $author=~s/\/home\/httpd\/html\/res\/([^\/]*)\/([^\/]*).*/$1\/$2/;
+    Debug("     after big regsub: $author");
     my ($udom,$uname)=split(/\//,$author);
+    Debug("      domain: $udom  user: $uname");
     my $proname=propath($udom,$uname);
+    Debug("     path = $proname");
     if (-e $proname) {
 	return 'owner';
     } else {
@@ -4286,15 +4297,25 @@
     my $expr='^'.$hostid.':'.$ip.':';
     $expr =~ s/\./\\\./g;
     my $sh;
+    Debug("Looking for $expr");
     if ($sh=IO::File->new("$fname.subscription")) {
 	while (my $subline=<$sh>) {
-	    if ($subline !~ /$expr/) {$contents.= $subline;} else {$found=1;}
+	    Debug("addline: line: $subline");
+	    if ($subline !~ /$expr/) {
+		$contents.= $subline;
+	    } else {
+		Debug("Found $subline");
+		$found=1;
+	    }
 	}
 	$sh->close();
     }
     $sh=IO::File->new(">$fname.subscription");
     if ($contents) { print $sh $contents; }
-    if ($newline) { print $sh $newline; }
+    if ($newline) { 
+	Debug("Appending $newline");
+	print $sh $newline; 
+    }
     $sh->close();
     return $found;
 }
@@ -4367,16 +4388,24 @@
 sub unsub {
     my ($fname,$clientip)=@_;
     my $result;
-    if (unlink("$fname.$clientname")) {
-	$result="ok\n";
-    } else {
-	$result="not_subscribed\n";
-    }
+#    if (unlink("$fname.$clientname")) {
+#	$result="ok\n";
+#    } else {
+#	$result="not_subscribed\n";
+#    }
+    unlink("$fname.$clientname");
     if (-e "$fname.subscription") {
+	Debug ("Processing subscription file $fname.subscription");
 	my $found=&addline($fname,$clientname,$clientip,'');
-	if ($found) { $result="ok\n"; }
+	if ($found) { 
+	    Debug("Old linek found");
+	    $result="ok\n"; 
+	} else {
+	    $result = "not_subscribed\n";
+	}
     } else {
-	if ($result != "ok\n") { $result="not_subscribed\n"; }
+	Debug("No Subscription file $fname.subscription");
+	if ($result ne "ok\n") { $result="not_subscribed\n"; }
     }
     return $result;
 }
@@ -4429,12 +4458,15 @@
 
 sub subscribe {
     my ($userinput,$clientip)=@_;
+    chomp($userinput);
     my $result;
     my ($cmd,$fname)=split(/:/,$userinput);
     my $ownership=&ishome($fname);
+    Debug("subscribe: Owner = $ownership file: '$fname'");
     if ($ownership eq 'owner') {
 # explitly asking for the current version?
         unless (-e $fname) {
+	    Debug("subscribe - does not exist");
             my $currentversion=&currentversion($fname);
 	    if (&thisversion($fname)==$currentversion) {
                 if ($fname=~/^(.+)\.\d+\.(\w+(?:\.meta)*)$/) {
@@ -4450,6 +4482,7 @@
             }
         }
 	if (-e $fname) {
+	    Debug("subscribe - exists");
 	    if (-d $fname) {
 		$result="directory\n";
 	    } else {