Completed object serialization
authorJamie Cameron <jcameron@webmin.com>
Sat, 6 Dec 2008 23:37:21 +0000 (23:37 +0000)
committerJamie Cameron <jcameron@webmin.com>
Sat, 6 Dec 2008 23:37:21 +0000 (23:37 +0000)
CHANGELOG
web-lib-funcs.pl

index 855c9a6..d968793 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -106,3 +106,4 @@ When a user whose password is close to expiry or has already expired logs in, a
 Many Japanese translation updates, thanks to Kazuya Masuda.
 ---- Changes since 1.440 ----
 Russian translation updates, thanks to Anton Statutov.
+Webmin's serialization functions can now handle objects, which allows them to be passed as parameters to remote function calls. Both caller and recipient must have the object's class installed though.
index 7184344..1a02571 100755 (executable)
@@ -4595,6 +4595,13 @@ elsif ($r eq 'HASH') {
 elsif ($r eq 'REF') {
        $rv = &serialise_variable(${$_[0]});
        }
+elsif ($r) {
+       # An object - treat as a hash
+       $r = "OBJECT ".&urlize($r);
+       $rv = join(",", map { &urlize(&serialise_variable($_)).",".
+                             &urlize(&serialise_variable($_[0]->{$_})) }
+                           keys %{$_[0]});
+       }
 return ($r ? $r : 'VAL').",".$rv;
 }
 
@@ -4633,6 +4640,17 @@ elsif ($v[0] eq 'REF') {
 elsif ($v[0] eq 'UNDEF') {
        $rv = undef;
        }
+elsif ($v[0] =~ /^OBJECT\s+(.*)$/) {
+       # An object hash that we have to re-bless
+       local $cls = $1;
+       $rv = { };
+       for($i=1; $i<@v; $i+=2) {
+               $rv->{&unserialise_variable(&un_urlize($v[$i]))} =
+                       &unserialise_variable(&un_urlize($v[$i+1]));
+               }
+       eval "use $cls";
+       bless $rv, $cls;
+       }
 return $rv;
 }