Index: mollom.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mollom/mollom.inc,v
retrieving revision 1.1.2.6
diff -u -p -r1.1.2.6 mollom.inc
--- mollom.inc	11 Sep 2010 01:31:02 -0000	1.1.2.6
+++ mollom.inc	13 Sep 2010 23:41:38 -0000
@@ -68,24 +68,46 @@ function _mollom_authentication($public_
 function _mollom_retrieve_server_list() {
   // Start from a hard-coded list of servers.
   $servers = array('http://xmlrpc1.mollom.com', 'http://xmlrpc2.mollom.com', 'http://xmlrpc3.mollom.com');
+  $messages = array();
 
-  // Use the list of servers to retrieve a list of servers from mollom.com:
+  // mollom.getServerList cannot use mollom() as we need to prevent infinite
+  // recursion. In addition, we handle returned error codes differently here,
+  // since MOLLOM_REDIRECT and MOLLOM_REFRESH, as well as any other
+  // communication error requires us to skip to the next server to retrieve a
+  // new server list. We only ever abort, if a server returns MOLLOM_ERROR, in
+  // which case there must be a configuration error (e.g., invalid API keys).
+  $method = 'mollom.getServerList';
   foreach ($servers as $server) {
-    $result = xmlrpc($server . '/' . MOLLOM_API_VERSION, 'mollom.getServerList', _mollom_authentication());
-    if (!xmlrpc_error()) {
-      return $result;
-    }
-    else {
-      _mollom_watchdog(array(
-        'Error @errno %message from %server mollom.getServerList' => array(
-          '@errno' => xmlrpc_errno(),
+    $result = xmlrpc($server . '/' . MOLLOM_API_VERSION, $method, _mollom_authentication());
+    if ($result === FALSE && ($error = xmlrpc_error())) {
+      // In any case, log the error.
+      $messages[] = array(
+        'Error @errno from %server for %method: %message' => array(
+          '@errno' => $error->code,
           '%server' => $server,
-          '%message' => xmlrpc_error_msg(),
+          '%method' => $method,
+          '%message' => $error->message,
         ),
-      ), WATCHDOG_ERROR);
+      );
+      // Skip to the next server in case of any error, except if we have a
+      // MOLLOM_ERROR, which indicates a bogus configuration. In this case, stop
+      // trying, since all servers will fail.
+      if ($error->code === MOLLOM_ERROR) {
+        break;
+      }
+    }
+    // Otherwise, we have a valid result.
+    else {
+      break;
     }
   }
-
-  return xmlrpc_errno();
+  if (is_array($result)) {
+    _mollom_watchdog_multiple($messages, WATCHDOG_DEBUG);
+    return $result;
+  }
+  else {
+    _mollom_watchdog_multiple($messages, WATCHDOG_ERROR);
+    return xmlrpc_errno();
+  }
 }
 
