[Patch] XML_RPC
| From: | Matt Kane | Date: | Mon, 29 Mar 2004 14:53:44 +0000 |
| Subject: | [Patch] XML_RPC | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-26853@lists.php.net to get a copy of this message | ||
Hi,
Attached is a patch to make a few small enhancements to the
XML_RPC_Server class.
I've changed it to use call_user_func instead of eval'ing a string. As
well as being neater and allowing object methods to be called, this
permits constructs such as:
class MyRPCServer extends XML_RPC_Server
{
function MyRPCServer()
{
$this->XML_RPC_Server(array( "my.method" => array ("function"
=> array(&$this, 'foo'))));
}
function foo($m)
{
...
//do stuff
}
}
I've added is_callable checks before these functions are called,
returned error objects if needed.
I've also made simple string prefix matching use strpos instead of
ereg, for performance.
Regards,
Matt
--
Matt Kane, Lead Developer, Piradian Ltd.
? XML_RPC.patch Index: Server.php =================================================================== RCS file: /repository/pear/XML_RPC/Server.php,v retrieving revision 1.6 diff -u -r1.6 Server.php --- Server.php 15 Mar 2004 13:58:39 -0000 1.6 +++ Server.php 29 Mar 2004 14:17:38 -0000 @@ -58,7 +58,7 @@ $methName = $m->getParam(0); $methName = $methName->scalarval(); - if (ereg("^system\.", $methName)) { + if (strpos($methName, "system.") === 0) { $dmap = $XML_RPC_Server_dmap; $sysCall = 1; } else { @@ -100,7 +100,7 @@ $methName = $m->getParam(0); $methName = $methName->scalarval(); - if (ereg("^system\.", $methName)) { + if (strpos($methName, "system.") === 0) { $dmap = $XML_RPC_Server_dmap; $sysCall = 1; } else { @@ -261,14 +261,14 @@ XML_RPC_Server_debugmsg($plist); // now to deal with the method $methName = $XML_RPC_xh[$parser]['method']; - if (ereg("^system\.", $methName)) { + if (strpos($methName, "system.") === 0) { $dmap = $XML_RPC_Server_dmap; $sysCall = 1; } else { $dmap = $this->dmap; $sysCall = 0; } - if (isset($dmap[$methName]['function'])) { + if (isset($dmap[$methName]['function']) && is_callable($dmap[$methName]['function'])) { // dispatch if exists if (isset($dmap[$methName]['signature'])) { $sr = $this->verifySignature($m, @@ -277,9 +277,9 @@ if ( (!isset($dmap[$methName]['signature'])) || $sr[0]) { // if no signature or correct signature if ($sysCall) { - eval('$r=' . $dmap[$methName]['function'] . '($this, $m);'); + $r = call_user_func($dmap[$methName]['function'], $this, $m); } else { - eval('$r=' . $dmap[$methName]['function'] . '($m);'); + $r = call_user_func($dmap[$methName]['function'], $m); } } else { $r = new XML_RPC_Response(0, $XML_RPC_err["incorrect_params"],
? XML_RPC.patch Index: Server.php =================================================================== RCS file: /repository/pear/XML_RPC/Server.php,v retrieving revision 1.6 diff -u -r1.6 Server.php --- Server.php 15 Mar 2004 13:58:39 -0000 1.6 +++ Server.php 29 Mar 2004 14:17:38 -0000 @@ -58,7 +58,7 @@ $methName = $m->getParam(0); $methName = $methName->scalarval(); - if (ereg("^system\.", $methName)) { + if (strpos($methName, "system.") === 0) { $dmap = $XML_RPC_Server_dmap; $sysCall = 1; } else { @@ -100,7 +100,7 @@ $methName = $m->getParam(0); $methName = $methName->scalarval(); - if (ereg("^system\.", $methName)) { + if (strpos($methName, "system.") === 0) { $dmap = $XML_RPC_Server_dmap; $sysCall = 1; } else { @@ -261,14 +261,14 @@ XML_RPC_Server_debugmsg($plist); // now to deal with the method $methName = $XML_RPC_xh[$parser]['method']; - if (ereg("^system\.", $methName)) { + if (strpos($methName, "system.") === 0) { $dmap = $XML_RPC_Server_dmap; $sysCall = 1; } else { $dmap = $this->dmap; $sysCall = 0; } - if (isset($dmap[$methName]['function'])) { + if (isset($dmap[$methName]['function']) && is_callable($dmap[$methName]['function'])) { // dispatch if exists if (isset($dmap[$methName]['signature'])) { $sr = $this->verifySignature($m, @@ -277,9 +277,9 @@ if ( (!isset($dmap[$methName]['signature'])) || $sr[0]) { // if no signature or correct signature if ($sysCall) { - eval('$r=' . $dmap[$methName]['function'] . '($this, $m);'); + $r = call_user_func($dmap[$methName]['function'], $this, $m); } else { - eval('$r=' . $dmap[$methName]['function'] . '($m);'); + $r = call_user_func($dmap[$methName]['function'], $m); } } else { $r = new XML_RPC_Response(0, $XML_RPC_err["incorrect_params"],