From c9fa3eee9b33b3f5d20bd76bca7c5bfd8db64acd Mon Sep 17 00:00:00 2001
From: martinlanghoff <martinlanghoff>
Date: Tue, 16 Jan 2007 23:27:41 +0000
Subject: [PATCH] get_config() callers in new MNET code switched to expect a
 single value returned Again, this simplifies the logic in a few places.

---
 admin/mnet/trustedhosts.php | 11 ++++++++---
 mnet/xmlrpc/client.php      | 17 ++++++++---------
 mnet/xmlrpc/server.php      | 11 ++++++-----
 3 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/admin/mnet/trustedhosts.php b/admin/mnet/trustedhosts.php
index da015f68c1..0ea3505c0b 100644
--- a/admin/mnet/trustedhosts.php
+++ b/admin/mnet/trustedhosts.php
@@ -25,11 +25,16 @@
 
     $trusted_hosts = '';//array();
     $old_trusted_hosts = get_config('mnet', 'mnet_trusted_hosts');
+    if (!empty($old_trusted_hosts)) {
+        $old_trusted_hosts =  explode(',', $old_trusted_hosts);
+    } else {
+        $old_trusted_hosts = array();
+    }
 
     $test_ip_address = optional_param('testipaddress', NULL, PARAM_HOST);
     $in_range = false;
     if (!empty($test_ip_address)) {
-        foreach(explode(',', $old_trusted_hosts->value) as $host) {
+        foreach($old_trusted_hosts as $host) {
             list($network, $mask) = explode('/', $host.'/');
             if (empty($network)) continue;
             if (strlen($mask) == 0) $mask = 32;
@@ -54,8 +59,8 @@
             unset($address, $mask);
         }
         set_config('mnet_trusted_hosts', str_replace("\n", ',', $trusted_hosts), 'mnet');
-    } elseif (!empty($old_trusted_hosts->value)) {
-        foreach(explode(',', $old_trusted_hosts->value) as $host) {
+    } elseif (!empty($old_trusted_hosts)) {
+        foreach($old_trusted_hosts as $host) {
             list($address, $mask) = explode('/', $host.'/');
             if (empty($address)) continue;
             if (strlen($mask) == 0) $mask = 32;
diff --git a/mnet/xmlrpc/client.php b/mnet/xmlrpc/client.php
index 96e5f0d897..c18f3d4bf5 100644
--- a/mnet/xmlrpc/client.php
+++ b/mnet/xmlrpc/client.php
@@ -204,12 +204,13 @@ class mnet_xmlrpc_client {
 
             if (!$isOpen) {
                 // Decryption failed... let's try our archived keys
-                $result = get_config('mnet', 'openssl_history');
-                if(empty($result)) {
-                    set_config('openssl_history', serialize(array()), 'mnet');
-                    $result = get_config('mnet', 'openssl_history');
+                $openssl_history = get_config('mnet', 'openssl_history');
+                if(empty($openssl_history)) {
+                    $openssl_history = array();
+                    set_config('openssl_history', serialize($openssl_history), 'mnet');
+                } else {
+                    $openssl_history = unserialize($result);
                 }
-                $openssl_history = unserialize($result->value);
                 foreach($openssl_history as $keyset) {
                     $keyresource = openssl_pkey_get_private($keyset['keypair_PEM']);
                     $isOpen      = openssl_open(base64_decode($data), $payload, base64_decode($key), $keyresource);
@@ -247,15 +248,13 @@ class mnet_xmlrpc_client {
         $remote_timestamp = $sig_parser->remote_timestamp - $hysteresis;
         $time_offset      = $remote_timestamp - $timestamp_send;
         if ($time_offset > 0) {
-            $result = get_field('config_plugins', 'value', 'plugin', 'mnet', 'name', 'drift_threshold');
-            if(empty($result)) {
+            $threshold = get_config('mnet', 'drift_threshold');
+            if(empty($threshold)) {
                 // We decided 15 seconds was a pretty good arbitrary threshold
                 // for time-drift between servers, but you can customize this in
                 // the config_plugins table. It's not advised though.
                 set_config('drift_threshold', 15, 'mnet');
                 $threshold = 15;
-            } else {
-                $threshold = $result;
             }
             if ($time_offset > $threshold) {
                 $this->error[] = 'Time gap with '.$mnet_peer->name.' ('.$time_offset.' seconds) is greater than the permitted maximum of '.$threshold.' seconds';
diff --git a/mnet/xmlrpc/server.php b/mnet/xmlrpc/server.php
index ad36654b01..90b3dfe730 100644
--- a/mnet/xmlrpc/server.php
+++ b/mnet/xmlrpc/server.php
@@ -145,12 +145,13 @@ function mnet_server_strip_wrappers($HTTP_RAW_POST_DATA) {
 
             if (!$isOpen) {
                 // Decryption failed... let's try our archived keys
-                $result = get_config('mnet', 'openssl_history');
-                if(empty($result)) {
-                    set_config('openssl_history', serialize(array()), 'mnet');
-                    $result = get_config('mnet', 'openssl_history');
+                $openssl_history = get_config('mnet', 'openssl_history');
+                if(empty($openssl_history)) {
+                    $openssl_history = array();
+                    set_config('openssl_history', serialize($openssl_history), 'mnet');
+                } else {
+                    $openssl_history = unserialize($result);
                 }
-                $openssl_history = unserialize($result->value);
                 foreach($openssl_history as $keyset) {
                     $keyresource = openssl_pkey_get_private($keyset['keypair_PEM']);
                     $isOpen      = openssl_open(base64_decode($data), $payload, base64_decode($key), $keyresource);
-- 
2.39.5