Example #1
0
/**
 * Forward an xmlrpc request to another server, and return to client the response received.
 *
 * DO NOT RUN AS IS IN PRODUCTION - this is an open relay !!!
 *
 * @param PhpXmlRpc\Request $req (see method docs below for a description of the expected parameters)
 *
 * @return PhpXmlRpc\Response
 */
function forward_request($req)
{
    $encoder = new \PhpXmlRpc\Encoder();
    // create client
    $timeout = 0;
    $url = $encoder->decode($req->getParam(0));
    $client = new PhpXmlRpc\Client($url);
    if ($req->getNumParams() > 3) {
        // we have to set some options onto the client.
        // Note that if we do not untaint the received values, warnings might be generated...
        $options = $encoder->decode($req->getParam(3));
        foreach ($options as $key => $val) {
            switch ($key) {
                case 'Cookie':
                    break;
                case 'Credentials':
                    break;
                case 'RequestCompression':
                    $client->setRequestCompression($val);
                    break;
                case 'SSLVerifyHost':
                    $client->setSSLVerifyHost($val);
                    break;
                case 'SSLVerifyPeer':
                    $client->setSSLVerifyPeer($val);
                    break;
                case 'Timeout':
                    $timeout = (int) $val;
                    break;
            }
            // switch
        }
    }
    // build call for remote server
    /// @todo find a way to forward client info (such as IP) to server, either
    /// - as xml comments in the payload, or
    /// - using std http header conventions, such as X-forwarded-for...
    $reqMethod = $encoder->decode($req->getParam(1));
    $pars = $req->getParam(2);
    $req = new PhpXmlRpc\Request($reqMethod);
    foreach ($pars as $par) {
        $req->addParam($par);
    }
    // add debug info into response we give back to caller
    PhpXmlRpc\Server::xmlrpc_debugmsg("Sending to server {$url} the payload: " . $req->serialize());
    return $client->send($req, $timeout);
}
<html>
<head><title>xmlrpc - Getstatename demo</title></head>
<body>
<h1>Getstatename demo</h1>

<h2>Send a U.S. state number to the server and get back the state name</h2>

<h3>The code demonstrates usage of automatic encoding/decoding of php variables into xmlrpc values</h3>
<?php 
include_once __DIR__ . "/../../src/Autoloader.php";
PhpXmlRpc\Autoloader::register();
if (isset($_POST["stateno"]) && $_POST["stateno"] != "") {
    $stateNo = (int) $_POST["stateno"];
    $encoder = new PhpXmlRpc\Encoder();
    $req = new PhpXmlRpc\Request('examples.getStateName', array($encoder->encode($stateNo)));
    print "Sending the following request:<pre>\n\n" . htmlentities($req->serialize()) . "\n\n</pre>Debug info of server data follows...\n\n";
    $client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
    $client->setDebug(1);
    $r = $client->send($req);
    if (!$r->faultCode()) {
        $v = $r->value();
        print "<br/>State number <b>" . $stateNo . "</b> is <b>" . htmlspecialchars($encoder->decode($v)) . "</b><br/>";
    } else {
        print "An error occurred: ";
        print "Code: " . htmlspecialchars($r->faultCode()) . " Reason: '" . htmlspecialchars($r->faultString()) . "'</pre><br/>";
    }
} else {
    $stateNo = "";
}
print "<form action=\"getstatename.php\" method=\"POST\">\n<input name=\"stateno\" value=\"" . $stateNo . "\"><input type=\"submit\" value=\"go\" name=\"submit\"></form>\n<p>Enter a state number to query its name</p>";
?>
Example #3
0
}
$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
// First off, let's retrieve the list of methods available on the remote server
print "<h3>methods available at http://" . $client->server . $client->path . "</h3>\n";
$req = new PhpXmlRpc\Request('system.listMethods');
$resp = $client->send($req);
if ($resp->faultCode()) {
    display_error($resp);
} else {
    $v = $resp->value();
    // Then, retrieve the signature and help text of each available method
    foreach ($v as $methodName) {
        print "<h4>" . $methodName->scalarval() . "</h4>\n";
        // build messages first, add params later
        $m1 = new PhpXmlRpc\Request('system.methodHelp');
        $m2 = new PhpXmlRpc\Request('system.methodSignature');
        $val = new PhpXmlRpc\Value($methodName->scalarval(), "string");
        $m1->addParam($val);
        $m2->addParam($val);
        // Send multiple requests in one http call.
        // If server does not support multicall, client will automatically fall back to 2 separate calls
        $ms = array($m1, $m2);
        $rs = $client->send($ms);
        if ($rs[0]->faultCode()) {
            display_error($rs[0]);
        } else {
            $val = $rs[0]->value();
            $txt = $val->scalarval();
            if ($txt != "") {
                print "<h4>Documentation</h4><p>{$txt}</p>\n";
            } else {
Example #4
0
<html>
<head><title>xmlrpc</title></head>
<body>
<?php 
include_once __DIR__ . "/../vendor/autoload.php";
$req = new PhpXmlRpc\Request('examples.getStateName');
print "<h3>Testing value serialization</h3>\n";
$v = new PhpXmlRpc\Value(23, "int");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new PhpXmlRpc\Value("What are you saying? >> << &&");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new PhpXmlRpc\Value(array(new PhpXmlRpc\Value("ABCDEFHIJ"), new PhpXmlRpc\Value(1234, 'int'), new PhpXmlRpc\Value(1, 'boolean')), "array");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new PhpXmlRpc\Value(array("thearray" => new PhpXmlRpc\Value(array(new PhpXmlRpc\Value("ABCDEFHIJ"), new PhpXmlRpc\Value(1234, 'int'), new PhpXmlRpc\Value(1, 'boolean'), new PhpXmlRpc\Value(0, 'boolean'), new PhpXmlRpc\Value(true, 'boolean'), new PhpXmlRpc\Value(false, 'boolean')), "array"), "theint" => new PhpXmlRpc\Value(23, 'int'), "thestring" => new PhpXmlRpc\Value("foobarwhizz"), "thestruct" => new PhpXmlRpc\Value(array("one" => new PhpXmlRpc\Value(1, 'int'), "two" => new PhpXmlRpc\Value(2, 'int')), "struct")), "struct");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$w = new PhpXmlRpc\Value(array($v, new PhpXmlRpc\Value("That was the struct!")), "array");
print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
$w = new PhpXmlRpc\Value("Mary had a little lamb,\nWhose fleece was white as snow,\nAnd everywhere that Mary went\nthe lamb was sure to go.\n\nMary had a little lamb\nShe tied it to a pylon\nTen thousand volts went down its back\nAnd turned it into nylon", "base64");
print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
print "<PRE>Value of base64 string is: '" . $w->scalarval() . "'</PRE>";
$req->method('');
$req->addParam(new PhpXmlRpc\Value("41", "int"));
print "<h3>Testing request serialization</h3>\n";
$op = $req->serialize();
print "<PRE>" . htmlentities($op) . "</PRE>";
print "<h3>Testing ISO date format</h3><pre>\n";
$t = time();
$date = PhpXmlRpc\Helper\Date::iso8601Encode($t);
print "Now is {$t} --> {$date}\n";
print "Or in UTC, that is " . PhpXmlRpc\Helper\Date::iso8601Encode($t, 1) . "\n";
$tb = PhpXmlRpc\Helper\Date::iso8601Decode($date);
 public function testAutoCoDec()
 {
     $data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00');
     $data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1);
     $data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2);
     //$keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
     $v1 = php_xmlrpc_encode($data, array('auto_dates'));
     $v2 = php_xmlrpc_decode_xml($v1->serialize());
     $this->assertEquals($v1, $v2);
     $r1 = new PhpXmlRpc\Response($v1);
     $r2 = php_xmlrpc_decode_xml($r1->serialize());
     $r2->serialize();
     // needed to set internal member payload
     $this->assertEquals($r1, $r2);
     $m1 = new PhpXmlRpc\Request('hello dolly', array($v1));
     $m2 = php_xmlrpc_decode_xml($m1->serialize());
     $m2->serialize();
     // needed to set internal member payload
     $this->assertEquals($m1, $m2);
 }