PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Web Services » XML_RPC » Bug #1090

[Patch] Use call_user_func for function call and strpos for prefix match.

Details

Submitted2004-03-29 16:12 UTC
Frommatt at piradian dot net
Assignedssb
StatusClosed
PackageXML_RPC
PHP VersionIrrelevant
Roadmaps(Not assigned)

Comments

[2004-03-29 16:12 UTC] matt at piradian dot net

Description:
------------
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.

? 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"],

[2004-03-29 16:22 UTC] matt at piradian dot net

Patch without screwed-up linebreaks:
http://news.php.net/article.php?
group=php.pear.dev&article=26853

[2004-05-31 17:49 UTC] pierre at dotgeek dot org

This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pear.php.net.

In case this was a pear.php.net website problem, the change will show
up on the website in short time.

Thank you for the report, and for helping us make PEAR better.