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

albertel lon-capa-cvs@mail.lon-capa.org
Sat, 04 Mar 2006 04:25:32 -0000


albertel		Fri Mar  3 23:25:32 2006 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - added compatibility code for talking to servers that don't know putstore
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.715 loncom/lonnet/perl/lonnet.pm:1.716
--- loncom/lonnet/perl/lonnet.pm:1.715	Fri Mar  3 20:00:15 2006
+++ loncom/lonnet/perl/lonnet.pm	Fri Mar  3 23:25:31 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.715 2006/03/04 01:00:15 albertel Exp $
+# $Id: lonnet.pm,v 1.716 2006/03/04 04:25:31 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3005,12 +3005,13 @@
        $items.= &escape($key).'='.&freeze_escape($storehash->{$key}).'&';
    }
    $items=~s/\&$//;
-   $symb=&escape($symb);
-   $version=&escape($version);
+   my $esc_symb=&escape($symb);
+   my $esc_v=&escape($version);
    my $reply =
-       &reply("putstore:$udomain:$uname:$namespace:$symb:$version:$items",
+       &reply("putstore:$udomain:$uname:$namespace:$esc_symb:$esc_v:$items",
 	      $uhome);
    if ($reply eq 'unknown_cmd') {
+       # gfall back to way things use to be done
        return &old_putstore($namespace,$symb,$version,$storehash,$udomain,
 			    $uname);
    }
@@ -3018,7 +3019,30 @@
 }
 
 sub old_putstore {
-    
+    my ($namespace,$symb,$version,$storehash,$udomain,$uname)=@_;
+    if (!$udomain) { $udomain=$env{'user.domain'}; }
+    if (!$uname) { $uname=$env{'user.name'}; }
+    my $uhome=&homeserver($uname,$udomain);
+    my %newstorehash;
+    foreach (keys %$storehash) {
+	my $key = $version.':'.&escape($symb).':'.$_;
+	$newstorehash{$key} = $storehash->{$_};
+    }
+    my $items='';
+    my %allitems = ();
+    foreach (keys %newstorehash) {
+	if ($_ =~ m/^([^\:]+):([^\:]+):([^\:]+)$/) {
+	    my $key = $1.':keys:'.$2;
+	    $allitems{$key} .= $3.':';
+	}
+	$items.=$_.'='.&freeze_escape($newstorehash{$_}).'&';
+    }
+    foreach (keys %allitems) {
+	$allitems{$_} =~ s/\:$//;
+	$items.= $_.'='.$allitems{$_}.'&';
+    }
+    $items=~s/\&$//;
+    return &reply("put:$udomain:$uname:$namespace:$items",$uhome);
 }
 
 # ------------------------------------------------------ critical put interface
@@ -7279,14 +7303,10 @@
 
 =item *
 
-putstore($namespace,$storehash,$udomain,$uname) : stores hash in namesp
-keys used in storehash include version information (e.g., 1:$symb:message etc.) as
-used in records written by &store and retrieved by &restore.  This function 
-was created for use in editing discussion posts, without incrementing the
-version number included in the key for a particular post. The colon 
-separated list of attribute names (e.g., the value associated with the key 
-1:keys:$symb) is also generated and passed in the ampersand separated 
-items sent to lonnet::reply().  
+putstore($namespace,$symb,$version,$storehash,$udomain,$uname) :
+  replaces a &store() version of data with a replacement set of data
+  for a particular resource in a namespace passed in the $storehash hash 
+  reference
 
 =item *