Update indentation, whitespace and line breaks.
This commit is contained in:
parent
3bcff2fa86
commit
a4c5a0a229
|
@ -64,9 +64,6 @@ define('MOLLOM_REDIRECT', 1200);
|
||||||
*
|
*
|
||||||
* @see Event
|
* @see Event
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MollomPlugin extends Plugin
|
class MollomPlugin extends Plugin
|
||||||
{
|
{
|
||||||
public $public_key;
|
public $public_key;
|
||||||
|
@ -95,7 +92,7 @@ class MollomPlugin extends Plugin
|
||||||
// all good! :-)
|
// all good! :-)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,38 +107,39 @@ class MollomPlugin extends Plugin
|
||||||
}
|
}
|
||||||
return '127.0.0.1';
|
return '127.0.0.1';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call a remote procedure at the Mollom server. This function will
|
* Call a remote procedure at the Mollom server. This function will
|
||||||
* automatically add the information required to authenticate against
|
* automatically add the information required to authenticate against
|
||||||
* Mollom.
|
* Mollom.
|
||||||
*/
|
*/
|
||||||
function mollom($method, $data = array()) {
|
function mollom($method, $data = array()) {
|
||||||
if (!extension_loaded('xmlrpc')) {
|
if (!extension_loaded('xmlrpc')) {
|
||||||
if (!dl('xmlrpc.so')) {
|
if (!dl('xmlrpc.so')) {
|
||||||
common_log(LOG_ERR, "Can't pingback; xmlrpc extension not available.");
|
common_log(LOG_ERR, "Can't pingback; xmlrpc extension not available.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct the server URL:
|
// Construct the server URL:
|
||||||
$public_key = $this->public_key;
|
$public_key = $this->public_key;
|
||||||
// Retrieve the list of Mollom servers from the database:
|
// Retrieve the list of Mollom servers from the database:
|
||||||
$servers = $this->servers;
|
$servers = $this->servers;
|
||||||
|
|
||||||
if ($servers == NULL) {
|
if ($servers == NULL) {
|
||||||
// Retrieve a list of valid Mollom servers from mollom.com:
|
// Retrieve a list of valid Mollom servers from mollom.com:
|
||||||
$servers = $this->xmlrpc('http://xmlrpc.mollom.com/'. MOLLOM_API_VERSION, 'mollom.getServerList', $this->authentication());
|
$servers = $this->xmlrpc('http://xmlrpc.mollom.com/'. MOLLOM_API_VERSION, 'mollom.getServerList', $this->authentication());
|
||||||
|
|
||||||
// Store the list of servers in the database:
|
// Store the list of servers in the database:
|
||||||
// TODO! variable_set('mollom_servers', $servers);
|
// TODO! variable_set('mollom_servers', $servers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($servers)) {
|
if (is_array($servers)) {
|
||||||
// Send the request to the first server, if that fails, try the other servers in the list:
|
// Send the request to the first server, if that fails, try the other servers in the list:
|
||||||
foreach ($servers as $server) {
|
foreach ($servers as $server) {
|
||||||
$auth = $this->authentication();
|
$auth = $this->authentication();
|
||||||
$data = array_merge($data, $auth);
|
$data = array_merge($data, $auth);
|
||||||
$result = $this->xmlrpc($server .'/'. MOLLOM_API_VERSION, $method, $data);
|
$result = $this->xmlrpc($server .'/'. MOLLOM_API_VERSION, $method, $data);
|
||||||
|
|
||||||
// Debug output:
|
// Debug output:
|
||||||
if (isset($data['session_id'])) {
|
if (isset($data['session_id'])) {
|
||||||
common_debug("called $method at server $server with session ID '". $data['session_id'] ."'");
|
common_debug("called $method at server $server with session ID '". $data['session_id'] ."'");
|
||||||
|
@ -149,14 +147,14 @@ class MollomPlugin extends Plugin
|
||||||
else {
|
else {
|
||||||
common_debug("called $method at server $server with no session ID");
|
common_debug("called $method at server $server with no session ID");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($errno = $this->xmlrpc_errno()) {
|
if ($errno = $this->xmlrpc_errno()) {
|
||||||
common_log(LOG_ERR, sprintf('Error @errno: %s - %s - %s - <pre>%s</pre>', $this->xmlrpc_errno(), $server, $this->xmlrpc_error_msg(), $method, print_r($data, TRUE)));
|
common_log(LOG_ERR, sprintf('Error @errno: %s - %s - %s - <pre>%s</pre>', $this->xmlrpc_errno(), $server, $this->xmlrpc_error_msg(), $method, print_r($data, TRUE)));
|
||||||
|
|
||||||
if ($errno == MOLLOM_REFRESH) {
|
if ($errno == MOLLOM_REFRESH) {
|
||||||
// Retrieve a list of valid Mollom servers from mollom.com:
|
// Retrieve a list of valid Mollom servers from mollom.com:
|
||||||
$servers = $this->xmlrpc('http://xmlrpc.mollom.com/'. MOLLOM_API_VERSION, 'mollom.getServerList', $this->authentication());
|
$servers = $this->xmlrpc('http://xmlrpc.mollom.com/'. MOLLOM_API_VERSION, 'mollom.getServerList', $this->authentication());
|
||||||
|
|
||||||
// Store the updated list of servers in the database:
|
// Store the updated list of servers in the database:
|
||||||
//tODO variable_set('mollom_servers', $servers);
|
//tODO variable_set('mollom_servers', $servers);
|
||||||
}
|
}
|
||||||
|
@ -166,7 +164,7 @@ class MollomPlugin extends Plugin
|
||||||
else if ($errno == MOLLOM_REDIRECT) {
|
else if ($errno == MOLLOM_REDIRECT) {
|
||||||
// Do nothing, we select the next client automatically.
|
// Do nothing, we select the next client automatically.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the XMLRPC error:
|
// Reset the XMLRPC error:
|
||||||
$this->xmlrpc_error(0); // FIXME: this is crazy.
|
$this->xmlrpc_error(0); // FIXME: this is crazy.
|
||||||
}
|
}
|
||||||
|
@ -176,74 +174,73 @@ class MollomPlugin extends Plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If none of the servers worked, activate the fallback mechanism:
|
// If none of the servers worked, activate the fallback mechanism:
|
||||||
common_debug("none of the servers worked");
|
common_debug("none of the servers worked");
|
||||||
// _mollom_fallback();
|
// _mollom_fallback();
|
||||||
|
|
||||||
// If everything failed, we reset the server list to force Mollom to request a new list:
|
// If everything failed, we reset the server list to force Mollom to request a new list:
|
||||||
//TODO variable_set('mollom_servers', array());
|
//TODO variable_set('mollom_servers', array());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function generate an array with all the information required to
|
* This function generate an array with all the information required to
|
||||||
* authenticate against Mollom. To prevent that requests are forged and
|
* authenticate against Mollom. To prevent that requests are forged and
|
||||||
* that you are impersonated, each request is signed with a hash computed
|
* that you are impersonated, each request is signed with a hash computed
|
||||||
* based on a private key and a timestamp.
|
* based on a private key and a timestamp.
|
||||||
*
|
*
|
||||||
* Both the client and the server share the secret key that is used to
|
* Both the client and the server share the secret key that is used to
|
||||||
* create the authentication hash based on a timestamp. They both hash
|
* create the authentication hash based on a timestamp. They both hash
|
||||||
* the timestamp with the secret key, and if the hashes match, the
|
* the timestamp with the secret key, and if the hashes match, the
|
||||||
* authenticity of the message has been validated.
|
* authenticity of the message has been validated.
|
||||||
*
|
*
|
||||||
* To avoid that someone can intercept a (hash, timestamp)-pair and
|
* To avoid that someone can intercept a (hash, timestamp)-pair and
|
||||||
* use that to impersonate a client, Mollom will reject the request
|
* use that to impersonate a client, Mollom will reject the request
|
||||||
* when the timestamp is more than 15 minutes off.
|
* when the timestamp is more than 15 minutes off.
|
||||||
*
|
*
|
||||||
* Make sure your server's time is synchronized with the world clocks,
|
* Make sure your server's time is synchronized with the world clocks,
|
||||||
* and that you don't share your private key with anyone else.
|
* and that you don't share your private key with anyone else.
|
||||||
*/
|
*/
|
||||||
private function authentication() {
|
private function authentication() {
|
||||||
|
|
||||||
$public_key = $this->public_key;
|
$public_key = $this->public_key;
|
||||||
$private_key = $this->private_key;
|
$private_key = $this->private_key;
|
||||||
|
|
||||||
// Generate a timestamp according to the dateTime format (http://www.w3.org/TR/xmlschema-2/#dateTime):
|
// Generate a timestamp according to the dateTime format (http://www.w3.org/TR/xmlschema-2/#dateTime):
|
||||||
$time = gmdate("Y-m-d\TH:i:s.\\0\\0\\0O", time());
|
$time = gmdate("Y-m-d\TH:i:s.\\0\\0\\0O", time());
|
||||||
|
|
||||||
// Calculate a HMAC-SHA1 according to RFC2104 (http://www.ietf.org/rfc/rfc2104.txt):
|
// Calculate a HMAC-SHA1 according to RFC2104 (http://www.ietf.org/rfc/rfc2104.txt):
|
||||||
$hash = base64_encode(
|
$hash = base64_encode(
|
||||||
pack("H*", sha1((str_pad($private_key, 64, chr(0x00)) ^ (str_repeat(chr(0x5c), 64))) .
|
pack("H*", sha1((str_pad($private_key, 64, chr(0x00)) ^ (str_repeat(chr(0x5c), 64))) .
|
||||||
pack("H*", sha1((str_pad($private_key, 64, chr(0x00)) ^ (str_repeat(chr(0x36), 64))) .
|
pack("H*", sha1((str_pad($private_key, 64, chr(0x00)) ^ (str_repeat(chr(0x36), 64))) .
|
||||||
$time))))
|
$time))))
|
||||||
);
|
);
|
||||||
|
|
||||||
// Store everything in an array. Elsewhere in the code, we'll add the
|
// Store everything in an array. Elsewhere in the code, we'll add the
|
||||||
// acutal data before we pass it onto the XML-RPC library:
|
// acutal data before we pass it onto the XML-RPC library:
|
||||||
$data['public_key'] = $public_key;
|
$data['public_key'] = $public_key;
|
||||||
$data['time'] = $time;
|
$data['time'] = $time;
|
||||||
$data['hash'] = $hash;
|
$data['hash'] = $hash;
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function xmlrpc($url) {
|
function xmlrpc($url) {
|
||||||
//require_once './includes/xmlrpc.inc';
|
//require_once './includes/xmlrpc.inc';
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
return call_user_func_array(array('MollomPlugin', '_xmlrpc'), $args);
|
return call_user_func_array(array('MollomPlugin', '_xmlrpc'), $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively turn a data structure into objects with 'data' and 'type' attributes.
|
* Recursively turn a data structure into objects with 'data' and 'type' attributes.
|
||||||
*
|
*
|
||||||
* @param $data
|
* @param $data
|
||||||
* The data structure.
|
* The data structure.
|
||||||
* @param $type
|
* @param $type
|
||||||
* Optional type assign to $data.
|
* Optional type assign to $data.
|
||||||
* @return
|
* @return
|
||||||
* Object.
|
* Object.
|
||||||
*/
|
*/
|
||||||
function xmlrpc_value($data, $type = FALSE) {
|
function xmlrpc_value($data, $type = FALSE) {
|
||||||
$xmlrpc_value = new stdClass();
|
$xmlrpc_value = new stdClass();
|
||||||
$xmlrpc_value->data = $data;
|
$xmlrpc_value->data = $data;
|
||||||
|
@ -266,15 +263,15 @@ class MollomPlugin extends Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map PHP type to XML-RPC type.
|
* Map PHP type to XML-RPC type.
|
||||||
*
|
*
|
||||||
* @param $xmlrpc_value
|
* @param $xmlrpc_value
|
||||||
* Variable whose type should be mapped.
|
* Variable whose type should be mapped.
|
||||||
* @return
|
* @return
|
||||||
* XML-RPC type as string.
|
* XML-RPC type as string.
|
||||||
* @see
|
* @see
|
||||||
* http://www.xmlrpc.com/spec#scalars
|
* http://www.xmlrpc.com/spec#scalars
|
||||||
*/
|
*/
|
||||||
function xmlrpc_value_calculate_type(&$xmlrpc_value) {
|
function xmlrpc_value_calculate_type(&$xmlrpc_value) {
|
||||||
// http://www.php.net/gettype: Never use gettype() to test for a certain type [...] Instead, use the is_* functions.
|
// http://www.php.net/gettype: Never use gettype() to test for a certain type [...] Instead, use the is_* functions.
|
||||||
if (is_bool($xmlrpc_value->data)) {
|
if (is_bool($xmlrpc_value->data)) {
|
||||||
|
@ -304,95 +301,95 @@ class MollomPlugin extends Plugin
|
||||||
return 'string';
|
return 'string';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate XML representing the given value.
|
* Generate XML representing the given value.
|
||||||
*
|
*
|
||||||
* @param $xmlrpc_value
|
* @param $xmlrpc_value
|
||||||
* @return
|
* @return
|
||||||
* XML representation of value.
|
* XML representation of value.
|
||||||
*/
|
*/
|
||||||
function xmlrpc_value_get_xml($xmlrpc_value) {
|
function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
switch ($xmlrpc_value->type) {
|
switch ($xmlrpc_value->type) {
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
return '<boolean>'. (($xmlrpc_value->data) ? '1' : '0') .'</boolean>';
|
return '<boolean>'. (($xmlrpc_value->data) ? '1' : '0') .'</boolean>';
|
||||||
break;
|
break;
|
||||||
case 'int':
|
case 'int':
|
||||||
return '<int>'. $xmlrpc_value->data .'</int>';
|
return '<int>'. $xmlrpc_value->data .'</int>';
|
||||||
break;
|
break;
|
||||||
case 'double':
|
case 'double':
|
||||||
return '<double>'. $xmlrpc_value->data .'</double>';
|
return '<double>'. $xmlrpc_value->data .'</double>';
|
||||||
break;
|
break;
|
||||||
case 'string':
|
case 'string':
|
||||||
// Note: we don't escape apostrophes because of the many blogging clients
|
// Note: we don't escape apostrophes because of the many blogging clients
|
||||||
// that don't support numerical entities (and XML in general) properly.
|
// that don't support numerical entities (and XML in general) properly.
|
||||||
return '<string>'. htmlspecialchars($xmlrpc_value->data) .'</string>';
|
return '<string>'. htmlspecialchars($xmlrpc_value->data) .'</string>';
|
||||||
break;
|
break;
|
||||||
case 'array':
|
case 'array':
|
||||||
$return = '<array><data>'."\n";
|
$return = '<array><data>'."\n";
|
||||||
foreach ($xmlrpc_value->data as $item) {
|
foreach ($xmlrpc_value->data as $item) {
|
||||||
$return .= ' <value>'. $this->xmlrpc_value_get_xml($item) ."</value>\n";
|
$return .= ' <value>'. $this->xmlrpc_value_get_xml($item) ."</value>\n";
|
||||||
|
}
|
||||||
|
$return .= '</data></array>';
|
||||||
|
return $return;
|
||||||
|
break;
|
||||||
|
case 'struct':
|
||||||
|
$return = '<struct>'."\n";
|
||||||
|
foreach ($xmlrpc_value->data as $name => $value) {
|
||||||
|
$return .= " <member><name>". htmlentities($name) ."</name><value>";
|
||||||
|
$return .= $this->xmlrpc_value_get_xml($value) ."</value></member>\n";
|
||||||
|
}
|
||||||
|
$return .= '</struct>';
|
||||||
|
return $return;
|
||||||
|
break;
|
||||||
|
case 'date':
|
||||||
|
return $this->xmlrpc_date_get_xml($xmlrpc_value->data);
|
||||||
|
break;
|
||||||
|
case 'base64':
|
||||||
|
return $this->xmlrpc_base64_get_xml($xmlrpc_value->data);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$return .= '</data></array>';
|
return FALSE;
|
||||||
return $return;
|
}
|
||||||
break;
|
|
||||||
case 'struct':
|
|
||||||
$return = '<struct>'."\n";
|
|
||||||
foreach ($xmlrpc_value->data as $name => $value) {
|
|
||||||
$return .= " <member><name>". htmlentities($name) ."</name><value>";
|
|
||||||
$return .= $this->xmlrpc_value_get_xml($value) ."</value></member>\n";
|
|
||||||
}
|
|
||||||
$return .= '</struct>';
|
|
||||||
return $return;
|
|
||||||
break;
|
|
||||||
case 'date':
|
|
||||||
return $this->xmlrpc_date_get_xml($xmlrpc_value->data);
|
|
||||||
break;
|
|
||||||
case 'base64':
|
|
||||||
return $this->xmlrpc_base64_get_xml($xmlrpc_value->data);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform an HTTP request.
|
* Perform an HTTP request.
|
||||||
*
|
*
|
||||||
* This is a flexible and powerful HTTP client implementation. Correctly handles
|
* This is a flexible and powerful HTTP client implementation. Correctly handles
|
||||||
* GET, POST, PUT or any other HTTP requests. Handles redirects.
|
* GET, POST, PUT or any other HTTP requests. Handles redirects.
|
||||||
*
|
*
|
||||||
* @param $url
|
* @param $url
|
||||||
* A string containing a fully qualified URI.
|
* A string containing a fully qualified URI.
|
||||||
* @param $headers
|
* @param $headers
|
||||||
* An array containing an HTTP header => value pair.
|
* An array containing an HTTP header => value pair.
|
||||||
* @param $method
|
* @param $method
|
||||||
* A string defining the HTTP request to use.
|
* A string defining the HTTP request to use.
|
||||||
* @param $data
|
* @param $data
|
||||||
* A string containing data to include in the request.
|
* A string containing data to include in the request.
|
||||||
* @param $retry
|
* @param $retry
|
||||||
* An integer representing how many times to retry the request in case of a
|
* An integer representing how many times to retry the request in case of a
|
||||||
* redirect.
|
* redirect.
|
||||||
* @return
|
* @return
|
||||||
* An object containing the HTTP request headers, response code, headers,
|
* An object containing the HTTP request headers, response code, headers,
|
||||||
* data and redirect status.
|
* data and redirect status.
|
||||||
*/
|
*/
|
||||||
function http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) {
|
function http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) {
|
||||||
global $db_prefix;
|
global $db_prefix;
|
||||||
|
|
||||||
$result = new stdClass();
|
$result = new stdClass();
|
||||||
|
|
||||||
// Parse the URL and make sure we can handle the schema.
|
// Parse the URL and make sure we can handle the schema.
|
||||||
$uri = parse_url($url);
|
$uri = parse_url($url);
|
||||||
|
|
||||||
if ($uri == FALSE) {
|
if ($uri == FALSE) {
|
||||||
$result->error = 'unable to parse URL';
|
$result->error = 'unable to parse URL';
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($uri['scheme'])) {
|
if (!isset($uri['scheme'])) {
|
||||||
$result->error = 'missing schema';
|
$result->error = 'missing schema';
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($uri['scheme']) {
|
switch ($uri['scheme']) {
|
||||||
case 'http':
|
case 'http':
|
||||||
$port = isset($uri['port']) ? $uri['port'] : 80;
|
$port = isset($uri['port']) ? $uri['port'] : 80;
|
||||||
|
@ -409,29 +406,29 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
$result->error = 'invalid schema '. $uri['scheme'];
|
$result->error = 'invalid schema '. $uri['scheme'];
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the socket opened properly.
|
// Make sure the socket opened properly.
|
||||||
if (!$fp) {
|
if (!$fp) {
|
||||||
// When a network error occurs, we use a negative number so it does not
|
// When a network error occurs, we use a negative number so it does not
|
||||||
// clash with the HTTP status codes.
|
// clash with the HTTP status codes.
|
||||||
$result->code = -$errno;
|
$result->code = -$errno;
|
||||||
$result->error = trim($errstr);
|
$result->error = trim($errstr);
|
||||||
|
|
||||||
// Mark that this request failed. This will trigger a check of the web
|
// Mark that this request failed. This will trigger a check of the web
|
||||||
// server's ability to make outgoing HTTP requests the next time that
|
// server's ability to make outgoing HTTP requests the next time that
|
||||||
// requirements checking is performed.
|
// requirements checking is performed.
|
||||||
// @see system_requirements()
|
// @see system_requirements()
|
||||||
//TODO variable_set('drupal_http_request_fails', TRUE);
|
//TODO variable_set('drupal_http_request_fails', TRUE);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct the path to act on.
|
// Construct the path to act on.
|
||||||
$path = isset($uri['path']) ? $uri['path'] : '/';
|
$path = isset($uri['path']) ? $uri['path'] : '/';
|
||||||
if (isset($uri['query'])) {
|
if (isset($uri['query'])) {
|
||||||
$path .= '?'. $uri['query'];
|
$path .= '?'. $uri['query'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create HTTP request.
|
// Create HTTP request.
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
// RFC 2616: "non-standard ports MUST, default ports MAY be included".
|
// RFC 2616: "non-standard ports MUST, default ports MAY be included".
|
||||||
|
@ -441,12 +438,12 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
'User-Agent' => 'User-Agent: Drupal (+http://drupal.org/)',
|
'User-Agent' => 'User-Agent: Drupal (+http://drupal.org/)',
|
||||||
'Content-Length' => 'Content-Length: '. strlen($data)
|
'Content-Length' => 'Content-Length: '. strlen($data)
|
||||||
);
|
);
|
||||||
|
|
||||||
// If the server url has a user then attempt to use basic authentication
|
// If the server url has a user then attempt to use basic authentication
|
||||||
if (isset($uri['user'])) {
|
if (isset($uri['user'])) {
|
||||||
$defaults['Authorization'] = 'Authorization: Basic '. base64_encode($uri['user'] . (!empty($uri['pass']) ? ":". $uri['pass'] : ''));
|
$defaults['Authorization'] = 'Authorization: Basic '. base64_encode($uri['user'] . (!empty($uri['pass']) ? ":". $uri['pass'] : ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the database prefix is being used by SimpleTest to run the tests in a copied
|
// If the database prefix is being used by SimpleTest to run the tests in a copied
|
||||||
// database then set the user-agent header to the database prefix so that any
|
// database then set the user-agent header to the database prefix so that any
|
||||||
// calls to other Drupal pages will run the SimpleTest prefixed database. The
|
// calls to other Drupal pages will run the SimpleTest prefixed database. The
|
||||||
|
@ -456,34 +453,34 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
if (is_string($db_prefix) && preg_match("/^simpletest\d+$/", $db_prefix, $matches)) {
|
if (is_string($db_prefix) && preg_match("/^simpletest\d+$/", $db_prefix, $matches)) {
|
||||||
$defaults['User-Agent'] = 'User-Agent: ' . $matches[0];
|
$defaults['User-Agent'] = 'User-Agent: ' . $matches[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($headers as $header => $value) {
|
foreach ($headers as $header => $value) {
|
||||||
$defaults[$header] = $header .': '. $value;
|
$defaults[$header] = $header .': '. $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$request = $method .' '. $path ." HTTP/1.0\r\n";
|
$request = $method .' '. $path ." HTTP/1.0\r\n";
|
||||||
$request .= implode("\r\n", $defaults);
|
$request .= implode("\r\n", $defaults);
|
||||||
$request .= "\r\n\r\n";
|
$request .= "\r\n\r\n";
|
||||||
$request .= $data;
|
$request .= $data;
|
||||||
|
|
||||||
$result->request = $request;
|
$result->request = $request;
|
||||||
|
|
||||||
fwrite($fp, $request);
|
fwrite($fp, $request);
|
||||||
|
|
||||||
// Fetch response.
|
// Fetch response.
|
||||||
$response = '';
|
$response = '';
|
||||||
while (!feof($fp) && $chunk = fread($fp, 1024)) {
|
while (!feof($fp) && $chunk = fread($fp, 1024)) {
|
||||||
$response .= $chunk;
|
$response .= $chunk;
|
||||||
}
|
}
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
|
|
||||||
// Parse response.
|
// Parse response.
|
||||||
list($split, $result->data) = explode("\r\n\r\n", $response, 2);
|
list($split, $result->data) = explode("\r\n\r\n", $response, 2);
|
||||||
$split = preg_split("/\r\n|\n|\r/", $split);
|
$split = preg_split("/\r\n|\n|\r/", $split);
|
||||||
|
|
||||||
list($protocol, $code, $text) = explode(' ', trim(array_shift($split)), 3);
|
list($protocol, $code, $text) = explode(' ', trim(array_shift($split)), 3);
|
||||||
$result->headers = array();
|
$result->headers = array();
|
||||||
|
|
||||||
// Parse headers.
|
// Parse headers.
|
||||||
while ($line = trim(array_shift($split))) {
|
while ($line = trim(array_shift($split))) {
|
||||||
list($header, $value) = explode(':', $line, 2);
|
list($header, $value) = explode(':', $line, 2);
|
||||||
|
@ -496,7 +493,7 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
$result->headers[$header] = trim($value);
|
$result->headers[$header] = trim($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$responses = array(
|
$responses = array(
|
||||||
100 => 'Continue', 101 => 'Switching Protocols',
|
100 => 'Continue', 101 => 'Switching Protocols',
|
||||||
200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content',
|
200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content',
|
||||||
|
@ -509,7 +506,7 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
if (!isset($responses[$code])) {
|
if (!isset($responses[$code])) {
|
||||||
$code = floor($code / 100) * 100;
|
$code = floor($code / 100) * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($code) {
|
switch ($code) {
|
||||||
case 200: // OK
|
case 200: // OK
|
||||||
case 304: // Not modified
|
case 304: // Not modified
|
||||||
|
@ -518,30 +515,30 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
case 302: // Moved temporarily
|
case 302: // Moved temporarily
|
||||||
case 307: // Moved temporarily
|
case 307: // Moved temporarily
|
||||||
$location = $result->headers['Location'];
|
$location = $result->headers['Location'];
|
||||||
|
|
||||||
if ($retry) {
|
if ($retry) {
|
||||||
$result = drupal_http_request($result->headers['Location'], $headers, $method, $data, --$retry);
|
$result = drupal_http_request($result->headers['Location'], $headers, $method, $data, --$retry);
|
||||||
$result->redirect_code = $result->code;
|
$result->redirect_code = $result->code;
|
||||||
}
|
}
|
||||||
$result->redirect_url = $location;
|
$result->redirect_url = $location;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$result->error = $text;
|
$result->error = $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result->code = $code;
|
$result->code = $code;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an object representing an XML-RPC message.
|
* Construct an object representing an XML-RPC message.
|
||||||
*
|
*
|
||||||
* @param $message
|
* @param $message
|
||||||
* String containing XML as defined at http://www.xmlrpc.com/spec
|
* String containing XML as defined at http://www.xmlrpc.com/spec
|
||||||
* @return
|
* @return
|
||||||
* Object
|
* Object
|
||||||
*/
|
*/
|
||||||
function xmlrpc_message($message) {
|
function xmlrpc_message($message) {
|
||||||
$xmlrpc_message = new stdClass();
|
$xmlrpc_message = new stdClass();
|
||||||
$xmlrpc_message->array_structs = array(); // The stack used to keep track of the current array/struct
|
$xmlrpc_message->array_structs = array(); // The stack used to keep track of the current array/struct
|
||||||
|
@ -552,14 +549,14 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse an XML-RPC message. If parsing fails, the faultCode and faultString
|
* Parse an XML-RPC message. If parsing fails, the faultCode and faultString
|
||||||
* will be added to the message object.
|
* will be added to the message object.
|
||||||
*
|
*
|
||||||
* @param $xmlrpc_message
|
* @param $xmlrpc_message
|
||||||
* Object generated by xmlrpc_message()
|
* Object generated by xmlrpc_message()
|
||||||
* @return
|
* @return
|
||||||
* TRUE if parsing succeeded; FALSE otherwise
|
* TRUE if parsing succeeded; FALSE otherwise
|
||||||
*/
|
*/
|
||||||
function xmlrpc_message_parse(&$xmlrpc_message) {
|
function xmlrpc_message_parse(&$xmlrpc_message) {
|
||||||
// First remove the XML declaration
|
// First remove the XML declaration
|
||||||
$xmlrpc_message->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $xmlrpc_message->message);
|
$xmlrpc_message->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $xmlrpc_message->message);
|
||||||
|
@ -587,13 +584,13 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a copy of the $xmlrpc_message object temporarily.
|
* Store a copy of the $xmlrpc_message object temporarily.
|
||||||
*
|
*
|
||||||
* @param $value
|
* @param $value
|
||||||
* Object
|
* Object
|
||||||
* @return
|
* @return
|
||||||
* The most recently stored $xmlrpc_message
|
* The most recently stored $xmlrpc_message
|
||||||
*/
|
*/
|
||||||
function xmlrpc_message_set($value = NULL) {
|
function xmlrpc_message_set($value = NULL) {
|
||||||
static $xmlrpc_message;
|
static $xmlrpc_message;
|
||||||
if ($value) {
|
if ($value) {
|
||||||
|
@ -691,6 +688,7 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
$xmlrpc_message->methodname = trim($xmlrpc_message->current_tag_contents);
|
$xmlrpc_message->methodname = trim($xmlrpc_message->current_tag_contents);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value_flag) {
|
if ($value_flag) {
|
||||||
if (count($xmlrpc_message->array_structs ) > 0) {
|
if (count($xmlrpc_message->array_structs ) > 0) {
|
||||||
// Add value to struct or array
|
// Add value to struct or array
|
||||||
|
@ -715,15 +713,15 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an object representing an XML-RPC request
|
* Construct an object representing an XML-RPC request
|
||||||
*
|
*
|
||||||
* @param $method
|
* @param $method
|
||||||
* The name of the method to be called
|
* The name of the method to be called
|
||||||
* @param $args
|
* @param $args
|
||||||
* An array of parameters to send with the method.
|
* An array of parameters to send with the method.
|
||||||
* @return
|
* @return
|
||||||
* Object
|
* Object
|
||||||
*/
|
*/
|
||||||
function xmlrpc_request($method, $args) {
|
function xmlrpc_request($method, $args) {
|
||||||
$xmlrpc_request = new stdClass();
|
$xmlrpc_request = new stdClass();
|
||||||
$xmlrpc_request->method = $method;
|
$xmlrpc_request->method = $method;
|
||||||
|
@ -733,8 +731,9 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
|
||||||
<methodCall>
|
<methodCall>
|
||||||
<methodName>{$xmlrpc_request->method}</methodName>
|
<methodName>{$xmlrpc_request->method}</methodName>
|
||||||
<params>
|
<params>
|
||||||
|
|
||||||
EOD;
|
EOD;
|
||||||
|
|
||||||
foreach ($xmlrpc_request->args as $arg) {
|
foreach ($xmlrpc_request->args as $arg) {
|
||||||
$xmlrpc_request->xml .= '<param><value>';
|
$xmlrpc_request->xml .= '<param><value>';
|
||||||
$v = $this->xmlrpc_value($arg);
|
$v = $this->xmlrpc_value($arg);
|
||||||
|
@ -778,7 +777,7 @@ EOD;
|
||||||
</value>
|
</value>
|
||||||
</fault>
|
</fault>
|
||||||
</methodResponse>
|
</methodResponse>
|
||||||
|
|
||||||
EOD;
|
EOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -868,26 +867,25 @@ EOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the last XML-RPC client error number
|
* Returns the last XML-RPC client error number
|
||||||
*/
|
*/
|
||||||
function xmlrpc_errno() {
|
function xmlrpc_errno() {
|
||||||
$error = $this->xmlrpc_error();
|
$error = $this->xmlrpc_error();
|
||||||
return ($error != NULL ? $error->code : NULL);
|
return ($error != NULL ? $error->code : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the last XML-RPC client error message
|
* Returns the last XML-RPC client error message
|
||||||
*/
|
*/
|
||||||
function xmlrpc_error_msg() {
|
function xmlrpc_error_msg() {
|
||||||
$error = xmlrpc_error();
|
$error = xmlrpc_error();
|
||||||
return ($error != NULL ? $error->message : NULL);
|
return ($error != NULL ? $error->message : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears any previous error.
|
* Clears any previous error.
|
||||||
*/
|
*/
|
||||||
function xmlrpc_clear_error() {
|
function xmlrpc_clear_error() {
|
||||||
$this->xmlrpc_error(NULL, NULL, TRUE);
|
$this->xmlrpc_error(NULL, NULL, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,9 @@ addPlugin('Mollom',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
replace '...' with your own public and private keys for your site, which you can get from mollom.com
|
replace '...' with your own public and private keys for your site, which you can
|
||||||
|
get from mollom.com.
|
||||||
|
|
||||||
If you're using this plugin, i'd love to know about it -- shiny@cpan.org or shiny on freenode.
|
If you're using this plugin, i'd love to know about it -- shiny@cpan.org or
|
||||||
|
shiny on freenode.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user