first commit
This commit is contained in:
68
lib/phpxmlrpc/demo/client/agesort.php
Normal file
68
lib/phpxmlrpc/demo/client/agesort.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<html>
|
||||
<head><title>xmlrpc - Agesort demo</title></head>
|
||||
<body>
|
||||
<h1>Agesort demo</h1>
|
||||
|
||||
<h2>Send an array of 'name' => 'age' pairs to the server that will send it back sorted.</h2>
|
||||
|
||||
<h3>The source code demonstrates basic lib usage, including handling of xmlrpc arrays and structs</h3>
|
||||
|
||||
<p></p>
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . "/../../src/Autoloader.php";
|
||||
PhpXmlRpc\Autoloader::register();
|
||||
|
||||
$inAr = array("Dave" => 24, "Edd" => 45, "Joe" => 37, "Fred" => 27);
|
||||
print "This is the input data:<br/><pre>";
|
||||
foreach($inAr as $key => $val) {
|
||||
print $key . ", " . $val . "\n";
|
||||
}
|
||||
print "</pre>";
|
||||
|
||||
// create parameters from the input array: an xmlrpc array of xmlrpc structs
|
||||
$p = array();
|
||||
foreach ($inAr as $key => $val) {
|
||||
$p[] = new PhpXmlRpc\Value(
|
||||
array(
|
||||
"name" => new PhpXmlRpc\Value($key),
|
||||
"age" => new PhpXmlRpc\Value($val, "int")
|
||||
),
|
||||
"struct"
|
||||
);
|
||||
}
|
||||
$v = new PhpXmlRpc\Value($p, "array");
|
||||
print "Encoded into xmlrpc format it looks like this: <pre>\n" . htmlentities($v->serialize()) . "</pre>\n";
|
||||
|
||||
// create client and message objects
|
||||
$req = new PhpXmlRpc\Request('examples.sortByAge', array($v));
|
||||
$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
|
||||
|
||||
// set maximum debug level, to have the complete communication printed to screen
|
||||
$client->setDebug(2);
|
||||
|
||||
// send request
|
||||
print "Now sending request (detailed debug info follows)";
|
||||
$resp = $client->send($req);
|
||||
|
||||
// check response for errors, and take appropriate action
|
||||
if (!$resp->faultCode()) {
|
||||
print "The server gave me these results:<pre>";
|
||||
$value = $resp->value();
|
||||
foreach ($value as $struct) {
|
||||
$name = $struct["name"];
|
||||
$age = $struct["age"];
|
||||
print htmlspecialchars($name->scalarval()) . ", " . htmlspecialchars($age->scalarval()) . "\n";
|
||||
}
|
||||
|
||||
print "<hr/>For nerds: I got this value back<br/><pre>" .
|
||||
htmlentities($resp->serialize()) . "</pre><hr/>\n";
|
||||
} else {
|
||||
print "An error occurred:<pre>";
|
||||
print "Code: " . htmlspecialchars($resp->faultCode()) .
|
||||
"\nReason: '" . htmlspecialchars($resp->faultString()) . '\'</pre><hr/>';
|
||||
}
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
43
lib/phpxmlrpc/demo/client/getstatename.php
Normal file
43
lib/phpxmlrpc/demo/client/getstatename.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<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 = (integer)$_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\">
|
||||
<input name=\"stateno\" value=\"" . $stateNo . "\"><input type=\"submit\" value=\"go\" name=\"submit\"></form>
|
||||
<p>Enter a state number to query its name</p>";
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
86
lib/phpxmlrpc/demo/client/introspect.php
Normal file
86
lib/phpxmlrpc/demo/client/introspect.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<html>
|
||||
<head><title>xmlrpc - Introspect demo</title></head>
|
||||
<body>
|
||||
<h1>Introspect demo</h1>
|
||||
<h2>Query server for available methods and their description</h2>
|
||||
<h3>The code demonstrates usage of multicall and introspection methods</h3>
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . "/../../src/Autoloader.php";
|
||||
PhpXmlRpc\Autoloader::register();
|
||||
|
||||
function display_error($r)
|
||||
{
|
||||
print "An error occurred: ";
|
||||
print "Code: " . $r->faultCode()
|
||||
. " Reason: '" . $r->faultString() . "'<br/>";
|
||||
}
|
||||
|
||||
$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 {
|
||||
print "<p>No documentation available.</p>\n";
|
||||
}
|
||||
}
|
||||
if ($rs[1]->faultCode()) {
|
||||
display_error($rs[1]);
|
||||
} else {
|
||||
print "<h4>Signature</h4><p>\n";
|
||||
// note: using PhpXmlRpc\Encoder::decode() here would lead to cleaner code
|
||||
$val = $rs[1]->value();
|
||||
if ($val->kindOf() == "array") {
|
||||
foreach ($val as $x) {
|
||||
$ret = $x[0];
|
||||
print "<code>" . $ret->scalarval() . " "
|
||||
. $methodName->scalarval() . "(";
|
||||
if ($x->count() > 1) {
|
||||
for ($k = 1; $k < $x->count(); $k++) {
|
||||
$y = $x[$k];
|
||||
print $y->scalarval();
|
||||
if ($k < $x->count() - 1) {
|
||||
print ", ";
|
||||
}
|
||||
}
|
||||
}
|
||||
print ")</code><br/>\n";
|
||||
}
|
||||
} else {
|
||||
print "Signature unknown\n";
|
||||
}
|
||||
print "</p>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
66
lib/phpxmlrpc/demo/client/mail.php
Normal file
66
lib/phpxmlrpc/demo/client/mail.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
// Allow users to see the source of this file even if PHP is not configured for it
|
||||
if (isset($_GET['showSource']) && $_GET['showSource']) {
|
||||
highlight_file(__FILE__);
|
||||
die();
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head><title>xmlrpc - Mail demo</title></head>
|
||||
<body>
|
||||
<h1>Mail demo</h1>
|
||||
|
||||
<p>This form enables you to send mail via an XML-RPC server.
|
||||
When you press <kbd>Send</kbd> this page will reload, showing you the XML-RPC request sent to the host server, the
|
||||
XML-RPC response received and the internal evaluation done by the PHP implementation.</p>
|
||||
|
||||
<p>You can find the source to this page here: <a href="mail.php?showSource=1">mail.php</a><br/>
|
||||
And the source to a functionally identical mail-by-XML-RPC server in the file <a
|
||||
href="../server/server.php?showSource=1">server.php</a> included with the library (look for the 'mail_send'
|
||||
method)</p>
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . "/../../src/Autoloader.php";
|
||||
PhpXmlRpc\Autoloader::register();
|
||||
|
||||
if (isset($_POST["mailto"]) && $_POST["mailto"]) {
|
||||
$server = "http://phpxmlrpc.sourceforge.net/server.php";
|
||||
$req = new PhpXmlRpc\Request('mail.send', array(
|
||||
new PhpXmlRpc\Value($_POST["mailto"]),
|
||||
new PhpXmlRpc\Value($_POST["mailsub"]),
|
||||
new PhpXmlRpc\Value($_POST["mailmsg"]),
|
||||
new PhpXmlRpc\Value($_POST["mailfrom"]),
|
||||
new PhpXmlRpc\Value($_POST["mailcc"]),
|
||||
new PhpXmlRpc\Value($_POST["mailbcc"]),
|
||||
new PhpXmlRpc\Value("text/plain")
|
||||
));
|
||||
|
||||
$client = new PhpXmlRpc\Client($server);
|
||||
$client->setDebug(2);
|
||||
$resp = $client->send($req);
|
||||
if (!$resp->faultCode()) {
|
||||
print "Mail sent OK<br/>\n";
|
||||
} else {
|
||||
print "<fonr color=\"red\">";
|
||||
print "Mail send failed<br/>\n";
|
||||
print "Fault: ";
|
||||
print "Code: " . htmlspecialchars($resp->faultCode()) .
|
||||
" Reason: '" . htmlspecialchars($resp->faultString()) . "'<br/>";
|
||||
print "</font><br/>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
<form method="POST">
|
||||
From <input size="60" name="mailfrom" value=""/><br/>
|
||||
<hr/>
|
||||
To <input size="60" name="mailto" value=""/><br/>
|
||||
Cc <input size="60" name="mailcc" value=""/><br/>
|
||||
Bcc <input size="60" name="mailbcc" value=""/><br/>
|
||||
<hr/>
|
||||
Subject <input size="60" name="mailsub" value="A message from xmlrpc"/>
|
||||
<hr/>
|
||||
Body <textarea rows="7" cols="60" name="mailmsg">Your message here</textarea><br/>
|
||||
<input type="Submit" value="Send"/>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
60
lib/phpxmlrpc/demo/client/proxy.php
Normal file
60
lib/phpxmlrpc/demo/client/proxy.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<html>
|
||||
<head><title>xmlrpc - Proxy demo</title></head>
|
||||
<body>
|
||||
<h1>proxy demo</h1>
|
||||
<h2>Query server using a 'proxy' object</h2>
|
||||
<h3>The code demonstrates usage for the terminally lazy. For a more complete proxy, look at at the Wrapper class</h3>
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . "/../../src/Autoloader.php";
|
||||
PhpXmlRpc\Autoloader::register();
|
||||
|
||||
class PhpXmlRpcProxy
|
||||
{
|
||||
protected $client;
|
||||
protected $prefix = 'examples.';
|
||||
|
||||
public function __construct(PhpXmlRpc\Client $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates any method call to an xmlrpc call.
|
||||
*
|
||||
* @author Toth Istvan
|
||||
*
|
||||
* @param string $name remote function name. Will be prefixed
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
function __call($name, $arguments)
|
||||
{
|
||||
$encoder = new PhpXmlRpc\Encoder();
|
||||
$valueArray = array();
|
||||
foreach ($arguments as $parameter) {
|
||||
$valueArray[] = $encoder->encode($parameter);
|
||||
}
|
||||
|
||||
// just in case this was set to something else
|
||||
$this->client->return_type = 'phpvals';
|
||||
|
||||
$resp = $this->client->send(new PhpXmlRpc\Request($this->prefix.$name, $valueArray));
|
||||
|
||||
if ($resp->faultCode()) {
|
||||
throw new Exception($resp->faultString(), $resp->faultCode());
|
||||
} else {
|
||||
return $resp->value();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$stateNo = rand(1, 51);
|
||||
$proxy = new PhpXmlRpcProxy(new \PhpXmlRpc\Client('http://phpxmlrpc.sourceforge.net/server.php'));
|
||||
$stateName = $proxy->getStateName($stateNo);
|
||||
|
||||
echo "State $stateNo is ".htmlspecialchars($stateName);
|
||||
30
lib/phpxmlrpc/demo/client/which.php
Normal file
30
lib/phpxmlrpc/demo/client/which.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<html>
|
||||
<head><title>xmlrpc - Which toolkit demo</title></head>
|
||||
<body>
|
||||
<h1>Which toolkit demo</h1>
|
||||
<h2>Query server for toolkit information</h2>
|
||||
<h3>The code demonstrates usage of the PhpXmlRpc\Encoder class</h3>
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . "/../../src/Autoloader.php";
|
||||
PhpXmlRpc\Autoloader::register();
|
||||
|
||||
$req = new PhpXmlRpc\Request('interopEchoTests.whichToolkit', array());
|
||||
$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
|
||||
$resp = $client->send($req);
|
||||
if (!$resp->faultCode()) {
|
||||
$encoder = new PhpXmlRpc\Encoder();
|
||||
$value = $encoder->decode($resp->value());
|
||||
print "<pre>";
|
||||
print "name: " . htmlspecialchars($value["toolkitName"]) . "\n";
|
||||
print "version: " . htmlspecialchars($value["toolkitVersion"]) . "\n";
|
||||
print "docs: " . htmlspecialchars($value["toolkitDocsUrl"]) . "\n";
|
||||
print "os: " . htmlspecialchars($value["toolkitOperatingSystem"]) . "\n";
|
||||
print "</pre>";
|
||||
} else {
|
||||
print "An error occurred: ";
|
||||
print "Code: " . htmlspecialchars($resp->faultCode()) . " Reason: '" . htmlspecialchars($resp->faultString()) . "'\n";
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
53
lib/phpxmlrpc/demo/client/wrap.php
Normal file
53
lib/phpxmlrpc/demo/client/wrap.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<html>
|
||||
<head><title>xmlrpc - Webservice wrappper demo</title></head>
|
||||
<body>
|
||||
<h1>Webservice wrappper demo</h1>
|
||||
|
||||
<h2>Wrap methods exposed by server into php functions</h2>
|
||||
|
||||
<h3>The code demonstrates usage of some the most automagic client usage possible:<br/>
|
||||
1) client that returns php values instead of xmlrpc value objects<br/>
|
||||
2) wrapping of remote methods into php functions<br/>
|
||||
See also proxy.php for an alternative take
|
||||
</h3>
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . "/../../src/Autoloader.php";
|
||||
PhpXmlRpc\Autoloader::register();
|
||||
|
||||
$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
|
||||
$client->return_type = 'phpvals'; // let client give us back php values instead of xmlrpcvals
|
||||
$resp = $client->send(new PhpXmlRpc\Request('system.listMethods'));
|
||||
if ($resp->faultCode()) {
|
||||
echo "<p>Server methods list could not be retrieved: error {$resp->faultCode()} '" . htmlspecialchars($resp->faultString()) . "'</p>\n";
|
||||
} else {
|
||||
echo "<p>Server methods list retrieved, now wrapping it up...</p>\n<ul>\n";
|
||||
flush();
|
||||
|
||||
$callable = false;
|
||||
$wrapper = new PhpXmlRpc\Wrapper();
|
||||
foreach ($resp->value() as $methodName) {
|
||||
// $resp->value is an array of strings
|
||||
if ($methodName == 'examples.getStateName') {
|
||||
$callable = $wrapper->wrapXmlrpcMethod($client, $methodName);
|
||||
if ($callable) {
|
||||
echo "<li>Remote server method " . htmlspecialchars($methodName) . " wrapped into php function</li>\n";
|
||||
} else {
|
||||
echo "<li>Remote server method " . htmlspecialchars($methodName) . " could not be wrapped!</li>\n";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
echo "</ul>\n";
|
||||
flush();
|
||||
|
||||
if ($callable) {
|
||||
echo "Now testing function for remote method to convert U.S. state number into state name";
|
||||
$stateNum = rand(1, 51);
|
||||
// the 2nd parameter gets added to the closure - it is teh debug level to be used for the client
|
||||
$stateName = $callable($stateNum, 2);
|
||||
}
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
60
lib/phpxmlrpc/demo/demo1.xml
Normal file
60
lib/phpxmlrpc/demo/demo1.xml
Normal file
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0"?>
|
||||
<methodResponse>
|
||||
<params>
|
||||
<param>
|
||||
<value>
|
||||
<struct>
|
||||
<member>
|
||||
<name>thearray</name>
|
||||
<value>
|
||||
<array>
|
||||
<data>
|
||||
<value>
|
||||
<string>ABCDEFHIJ</string>
|
||||
</value>
|
||||
<value>
|
||||
<int>1234</int>
|
||||
</value>
|
||||
<value>
|
||||
<boolean>1</boolean>
|
||||
</value>
|
||||
</data>
|
||||
</array>
|
||||
</value>
|
||||
</member>
|
||||
<member>
|
||||
<name>theint</name>
|
||||
<value>
|
||||
<int>23</int>
|
||||
</value>
|
||||
</member>
|
||||
<member>
|
||||
<name>thestring</name>
|
||||
<value>
|
||||
<string>foobarwhizz</string>
|
||||
</value>
|
||||
</member>
|
||||
<member>
|
||||
<name>thestruct</name>
|
||||
<value>
|
||||
<struct>
|
||||
<member>
|
||||
<name>one</name>
|
||||
<value>
|
||||
<int>1</int>
|
||||
</value>
|
||||
</member>
|
||||
<member>
|
||||
<name>two</name>
|
||||
<value>
|
||||
<int>2</int>
|
||||
</value>
|
||||
</member>
|
||||
</struct>
|
||||
</value>
|
||||
</member>
|
||||
</struct>
|
||||
</value>
|
||||
</param>
|
||||
</params>
|
||||
</methodResponse>
|
||||
10
lib/phpxmlrpc/demo/demo2.xml
Normal file
10
lib/phpxmlrpc/demo/demo2.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0"?>
|
||||
<methodResponse>
|
||||
<params>
|
||||
<param>
|
||||
<value>
|
||||
<string>South Dakota's own</string>
|
||||
</value>
|
||||
</param>
|
||||
</params>
|
||||
</methodResponse>
|
||||
21
lib/phpxmlrpc/demo/demo3.xml
Normal file
21
lib/phpxmlrpc/demo/demo3.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0"?>
|
||||
<methodResponse>
|
||||
<fault>
|
||||
<value>
|
||||
<struct>
|
||||
<member>
|
||||
<name>faultCode</name>
|
||||
<value>
|
||||
<int>4</int>
|
||||
</value>
|
||||
</member>
|
||||
<member>
|
||||
<name>faultString</name>
|
||||
<value>
|
||||
<string>Too many parameters.</string>
|
||||
</value>
|
||||
</member>
|
||||
</struct>
|
||||
</value>
|
||||
</fault>
|
||||
</methodResponse>
|
||||
99
lib/phpxmlrpc/demo/server/discuss.php
Normal file
99
lib/phpxmlrpc/demo/server/discuss.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . "/../../vendor/autoload.php";
|
||||
|
||||
use PhpXmlRpc\Value;
|
||||
|
||||
$addComment_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcString, Value::$xmlrpcString, Value::$xmlrpcString));
|
||||
|
||||
$addComment_doc = 'Adds a comment to an item. The first parameter
|
||||
is the item ID, the second the name of the commenter, and the third
|
||||
is the comment itself. Returns the number of comments against that
|
||||
ID.';
|
||||
|
||||
function addComment($req)
|
||||
{
|
||||
$err = "";
|
||||
// since validation has already been carried out for us,
|
||||
// we know we got exactly 3 string values
|
||||
$encoder = new PhpXmlRpc\Encoder();
|
||||
$n = $encoder->decode($req);
|
||||
$msgID = $n[0];
|
||||
$name = $n[1];
|
||||
$comment = $n[2];
|
||||
|
||||
$dbh = dba_open("/tmp/comments.db", "c", "db2");
|
||||
if ($dbh) {
|
||||
$countID = "${msgID}_count";
|
||||
if (dba_exists($countID, $dbh)) {
|
||||
$count = dba_fetch($countID, $dbh);
|
||||
} else {
|
||||
$count = 0;
|
||||
}
|
||||
// add the new comment in
|
||||
dba_insert($msgID . "_comment_${count}", $comment, $dbh);
|
||||
dba_insert($msgID . "_name_${count}", $name, $dbh);
|
||||
$count++;
|
||||
dba_replace($countID, $count, $dbh);
|
||||
dba_close($dbh);
|
||||
} else {
|
||||
$err = "Unable to open comments database.";
|
||||
}
|
||||
// if we generated an error, create an error return response
|
||||
if ($err) {
|
||||
return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
|
||||
} else {
|
||||
// otherwise, we create the right response
|
||||
return new PhpXmlRpc\Response(new PhpXmlRpc\Value($count, "int"));
|
||||
}
|
||||
}
|
||||
|
||||
$getComments_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcString));
|
||||
|
||||
$getComments_doc = 'Returns an array of comments for a given ID, which
|
||||
is the sole argument. Each array item is a struct containing name
|
||||
and comment text.';
|
||||
|
||||
function getComments($req)
|
||||
{
|
||||
$err = "";
|
||||
$ra = array();
|
||||
$encoder = new PhpXmlRpc\Encoder();
|
||||
$msgID = $encoder->decode($req->getParam(0));
|
||||
$dbh = dba_open("/tmp/comments.db", "r", "db2");
|
||||
if ($dbh) {
|
||||
$countID = "${msgID}_count";
|
||||
if (dba_exists($countID, $dbh)) {
|
||||
$count = dba_fetch($countID, $dbh);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$name = dba_fetch("${msgID}_name_${i}", $dbh);
|
||||
$comment = dba_fetch("${msgID}_comment_${i}", $dbh);
|
||||
// push a new struct onto the return array
|
||||
$ra[] = array(
|
||||
"name" => $name,
|
||||
"comment" => $comment,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if we generated an error, create an error return response
|
||||
if ($err) {
|
||||
return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
|
||||
} else {
|
||||
// otherwise, we create the right response
|
||||
return new PhpXmlRpc\Response($encoder->encode($ra));
|
||||
}
|
||||
}
|
||||
|
||||
$srv = new PhpXmlRpc\Server(array(
|
||||
"discuss.addComment" => array(
|
||||
"function" => "addComment",
|
||||
"signature" => $addComment_sig,
|
||||
"docstring" => $addComment_doc,
|
||||
),
|
||||
"discuss.getComments" => array(
|
||||
"function" => "getComments",
|
||||
"signature" => $getComments_sig,
|
||||
"docstring" => $getComments_doc,
|
||||
),
|
||||
));
|
||||
88
lib/phpxmlrpc/demo/server/proxy.php
Normal file
88
lib/phpxmlrpc/demo/server/proxy.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* XMLRPC server acting as proxy for requests to other servers
|
||||
* (useful e.g. for ajax-originated calls that can only connect back to
|
||||
* the originating server).
|
||||
*
|
||||
* @author Gaetano Giunta
|
||||
* @copyright (C) 2006-2015 G. Giunta
|
||||
* @license code licensed under the BSD License: see file license.txt
|
||||
*/
|
||||
|
||||
include_once __DIR__ . "/../../src/Autoloader.php";
|
||||
PhpXmlRpc\Autoloader::register();
|
||||
|
||||
/**
|
||||
* 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 = (integer)$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);
|
||||
}
|
||||
|
||||
// run the server
|
||||
$server = new PhpXmlRpc\Server(
|
||||
array(
|
||||
'xmlrpcproxy.call' => array(
|
||||
'function' => 'forward_request',
|
||||
'signature' => array(
|
||||
array('mixed', 'string', 'string', 'array'),
|
||||
array('mixed', 'string', 'string', 'array', 'struct'),
|
||||
),
|
||||
'docstring' => 'forwards xmlrpc calls to remote servers. Returns remote method\'s response. Accepts params: remote server url (might include basic auth credentials), method name, array of params, and (optionally) a struct containing call options',
|
||||
),
|
||||
)
|
||||
);
|
||||
981
lib/phpxmlrpc/demo/server/server.php
Normal file
981
lib/phpxmlrpc/demo/server/server.php
Normal file
@@ -0,0 +1,981 @@
|
||||
<?php
|
||||
/**
|
||||
* Demo server for xmlrpc library.
|
||||
*
|
||||
* Implements a lot of webservices, including a suite of services used for
|
||||
* interoperability testing (validator1 methods), and some whose only purpose
|
||||
* is to be used for unit-testing the library.
|
||||
*
|
||||
* Please do not copy this file verbatim into your production server.
|
||||
**/
|
||||
|
||||
// give user a chance to see the source for this server instead of running the services
|
||||
if ($_SERVER['REQUEST_METHOD'] != 'POST' && isset($_GET['showSource'])) {
|
||||
highlight_file(__FILE__);
|
||||
die();
|
||||
}
|
||||
|
||||
include_once __DIR__ . "/../../vendor/autoload.php";
|
||||
|
||||
// out-of-band information: let the client manipulate the server operations.
|
||||
// we do this to help the testsuite script: do not reproduce in production!
|
||||
if (isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) && extension_loaded('xdebug')) {
|
||||
$GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] = '/tmp/phpxmlrpc_coverage';
|
||||
if (!is_dir($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'])) {
|
||||
mkdir($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY']);
|
||||
}
|
||||
|
||||
include_once __DIR__ . "/../../vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumCommon/prepend.php";
|
||||
}
|
||||
|
||||
use PhpXmlRpc\Value;
|
||||
|
||||
/**
|
||||
* Used to test usage of object methods in dispatch maps and in wrapper code.
|
||||
*/
|
||||
class xmlrpcServerMethodsContainer
|
||||
{
|
||||
/**
|
||||
* Method used to test logging of php warnings generated by user functions.
|
||||
* @param PhpXmlRpc\Request $req
|
||||
* @return PhpXmlRpc\Response
|
||||
*/
|
||||
public function phpWarningGenerator($req)
|
||||
{
|
||||
$a = $undefinedVariable; // this triggers a warning in E_ALL mode, since $undefinedVariable is undefined
|
||||
return new PhpXmlRpc\Response(new Value(1, Value::$xmlrpcBoolean));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to test catching of exceptions in the server.
|
||||
* @param PhpXmlRpc\Request $req
|
||||
* @throws Exception
|
||||
*/
|
||||
public function exceptionGenerator($req)
|
||||
{
|
||||
throw new Exception("it's just a test", 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $msg
|
||||
*/
|
||||
public function debugMessageGenerator($msg)
|
||||
{
|
||||
PhpXmlRpc\Server::xmlrpc_debugmsg($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* A PHP version of the state-number server. Send me an integer and i'll sell you a state.
|
||||
* Used to test wrapping of PHP methods into xmlrpc methods.
|
||||
*
|
||||
* @param integer $num
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function findState($num)
|
||||
{
|
||||
return inner_findstate($num);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of stdClass.
|
||||
* Used to test wrapping of PHP objects with class preservation
|
||||
*/
|
||||
public function returnObject()
|
||||
{
|
||||
$obj = new stdClass();
|
||||
$obj->hello = 'world';
|
||||
return $obj;
|
||||
}
|
||||
}
|
||||
|
||||
// a PHP version of the state-number server
|
||||
// send me an integer and i'll sell you a state
|
||||
|
||||
$stateNames = array(
|
||||
"Alabama", "Alaska", "Arizona", "Arkansas", "California",
|
||||
"Colorado", "Columbia", "Connecticut", "Delaware", "Florida",
|
||||
"Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas",
|
||||
"Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan",
|
||||
"Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada",
|
||||
"New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina",
|
||||
"North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island",
|
||||
"South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont",
|
||||
"Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming",
|
||||
);
|
||||
|
||||
$findstate_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcInt));
|
||||
$findstate_doc = 'When passed an integer between 1 and 51 returns the
|
||||
name of a US state, where the integer is the index of that state name
|
||||
in an alphabetic order.';
|
||||
|
||||
function findState($req)
|
||||
{
|
||||
global $stateNames;
|
||||
|
||||
$err = "";
|
||||
// get the first param
|
||||
$sno = $req->getParam(0);
|
||||
|
||||
// param must be there and of the correct type: server object does the validation for us
|
||||
|
||||
// extract the value of the state number
|
||||
$snv = $sno->scalarval();
|
||||
// look it up in our array (zero-based)
|
||||
if (isset($stateNames[$snv - 1])) {
|
||||
$stateName = $stateNames[$snv - 1];
|
||||
} else {
|
||||
// not there, so complain
|
||||
$err = "I don't have a state for the index '" . $snv . "'";
|
||||
}
|
||||
|
||||
// if we generated an error, create an error return response
|
||||
if ($err) {
|
||||
return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
|
||||
} else {
|
||||
// otherwise, we create the right response with the state name
|
||||
return new PhpXmlRpc\Response(new Value($stateName));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inner code of the state-number server.
|
||||
* Used to test wrapping of PHP functions into xmlrpc methods.
|
||||
*
|
||||
* @param integer $stateNo the state number
|
||||
*
|
||||
* @return string the name of the state (or error description)
|
||||
*
|
||||
* @throws Exception if state is not found
|
||||
*/
|
||||
function inner_findstate($stateNo)
|
||||
{
|
||||
global $stateNames;
|
||||
|
||||
if (isset($stateNames[$stateNo - 1])) {
|
||||
return $stateNames[$stateNo - 1];
|
||||
} else {
|
||||
// not, there so complain
|
||||
throw new Exception("I don't have a state for the index '" . $stateNo . "'", PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser);
|
||||
}
|
||||
}
|
||||
|
||||
$wrapper = new PhpXmlRpc\Wrapper();
|
||||
|
||||
$findstate2_sig = $wrapper->wrapPhpFunction('inner_findstate');
|
||||
|
||||
$findstate3_sig = $wrapper->wrapPhpFunction(array('xmlrpcServerMethodsContainer', 'findState'));
|
||||
|
||||
$obj = new xmlrpcServerMethodsContainer();
|
||||
$findstate4_sig = $wrapper->wrapPhpFunction(array($obj, 'findstate'));
|
||||
|
||||
$findstate5_sig = $wrapper->wrapPhpFunction('xmlrpcServerMethodsContainer::findState', '', array('return_source' => true));
|
||||
eval($findstate5_sig['source']);
|
||||
|
||||
$findstate6_sig = $wrapper->wrapPhpFunction('inner_findstate', '', array('return_source' => true));
|
||||
eval($findstate6_sig['source']);
|
||||
|
||||
$findstate7_sig = $wrapper->wrapPhpFunction(array('xmlrpcServerMethodsContainer', 'findState'), '', array('return_source' => true));
|
||||
eval($findstate7_sig['source']);
|
||||
|
||||
$obj = new xmlrpcServerMethodsContainer();
|
||||
$findstate8_sig = $wrapper->wrapPhpFunction(array($obj, 'findstate'), '', array('return_source' => true));
|
||||
eval($findstate8_sig['source']);
|
||||
|
||||
$findstate9_sig = $wrapper->wrapPhpFunction('xmlrpcServerMethodsContainer::findState', '', array('return_source' => true));
|
||||
eval($findstate9_sig['source']);
|
||||
|
||||
$findstate10_sig = array(
|
||||
"function" => function ($req) { return findState($req); },
|
||||
"signature" => $findstate_sig,
|
||||
"docstring" => $findstate_doc,
|
||||
);
|
||||
|
||||
$findstate11_sig = $wrapper->wrapPhpFunction(function ($stateNo) { return inner_findstate($stateNo); });
|
||||
|
||||
$c = new xmlrpcServerMethodsContainer;
|
||||
$moreSignatures = $wrapper->wrapPhpClass($c, array('prefix' => 'tests.', 'method_type' => 'all'));
|
||||
|
||||
$returnObj_sig = $wrapper->wrapPhpFunction(array($c, 'returnObject'), '', array('encode_php_objs' => true));
|
||||
|
||||
// used to test signatures with NULL params
|
||||
$findstate12_sig = array(
|
||||
array(Value::$xmlrpcString, Value::$xmlrpcInt, Value::$xmlrpcNull),
|
||||
array(Value::$xmlrpcString, Value::$xmlrpcNull, Value::$xmlrpcInt),
|
||||
);
|
||||
|
||||
function findStateWithNulls($req)
|
||||
{
|
||||
$a = $req->getParam(0);
|
||||
$b = $req->getParam(1);
|
||||
|
||||
if ($a->scalartyp() == Value::$xmlrpcNull)
|
||||
return new PhpXmlRpc\Response(new Value(inner_findstate($b->scalarval())));
|
||||
else
|
||||
return new PhpXmlRpc\Response(new Value(inner_findstate($a->scalarval())));
|
||||
}
|
||||
|
||||
$addtwo_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcInt, Value::$xmlrpcInt));
|
||||
$addtwo_doc = 'Add two integers together and return the result';
|
||||
function addTwo($req)
|
||||
{
|
||||
$s = $req->getParam(0);
|
||||
$t = $req->getParam(1);
|
||||
|
||||
return new PhpXmlRpc\Response(new Value($s->scalarval() + $t->scalarval(), Value::$xmlrpcInt));
|
||||
}
|
||||
|
||||
$addtwodouble_sig = array(array(Value::$xmlrpcDouble, Value::$xmlrpcDouble, Value::$xmlrpcDouble));
|
||||
$addtwodouble_doc = 'Add two doubles together and return the result';
|
||||
function addTwoDouble($req)
|
||||
{
|
||||
$s = $req->getParam(0);
|
||||
$t = $req->getParam(1);
|
||||
|
||||
return new PhpXmlRpc\Response(new Value($s->scalarval() + $t->scalarval(), Value::$xmlrpcDouble));
|
||||
}
|
||||
|
||||
$stringecho_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcString));
|
||||
$stringecho_doc = 'Accepts a string parameter, returns the string.';
|
||||
function stringEcho($req)
|
||||
{
|
||||
// just sends back a string
|
||||
return new PhpXmlRpc\Response(new Value($req->getParam(0)->scalarval()));
|
||||
}
|
||||
|
||||
$echoback_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcString));
|
||||
$echoback_doc = 'Accepts a string parameter, returns the entire incoming payload';
|
||||
function echoBack($req)
|
||||
{
|
||||
// just sends back a string with what i got sent to me, just escaped, that's all
|
||||
$s = "I got the following message:\n" . $req->serialize();
|
||||
|
||||
return new PhpXmlRpc\Response(new Value($s));
|
||||
}
|
||||
|
||||
$echosixtyfour_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcBase64));
|
||||
$echosixtyfour_doc = 'Accepts a base64 parameter and returns it decoded as a string';
|
||||
function echoSixtyFour($req)
|
||||
{
|
||||
// Accepts an encoded value, but sends it back as a normal string.
|
||||
// This is to test that base64 encoding is working as expected
|
||||
$incoming = $req->getParam(0);
|
||||
|
||||
return new PhpXmlRpc\Response(new Value($incoming->scalarval(), Value::$xmlrpcString));
|
||||
}
|
||||
|
||||
$bitflipper_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
|
||||
$bitflipper_doc = 'Accepts an array of booleans, and returns them inverted';
|
||||
function bitFlipper($req)
|
||||
{
|
||||
$v = $req->getParam(0);
|
||||
$rv = new Value(array(), Value::$xmlrpcArray);
|
||||
|
||||
foreach ($v as $b) {
|
||||
if ($b->scalarval()) {
|
||||
$rv[] = new Value(false, Value::$xmlrpcBoolean);
|
||||
} else {
|
||||
$rv[] = new Value(true, Value::$xmlrpcBoolean);
|
||||
}
|
||||
}
|
||||
|
||||
return new PhpXmlRpc\Response($rv);
|
||||
}
|
||||
|
||||
// Sorting demo
|
||||
//
|
||||
// send me an array of structs thus:
|
||||
//
|
||||
// Dave 35
|
||||
// Edd 45
|
||||
// Fred 23
|
||||
// Barney 37
|
||||
//
|
||||
// and I'll return it to you in sorted order
|
||||
|
||||
function agesorter_compare($a, $b)
|
||||
{
|
||||
global $agesorter_arr;
|
||||
|
||||
// don't even ask me _why_ these come padded with hyphens, I couldn't tell you :p
|
||||
$a = str_replace("-", "", $a);
|
||||
$b = str_replace("-", "", $b);
|
||||
|
||||
if ($agesorter_arr[$a] == $agesorter_arr[$b]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ($agesorter_arr[$a] > $agesorter_arr[$b]) ? -1 : 1;
|
||||
}
|
||||
|
||||
$agesorter_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
|
||||
$agesorter_doc = 'Send this method an array of [string, int] structs, eg:
|
||||
<pre>
|
||||
Dave 35
|
||||
Edd 45
|
||||
Fred 23
|
||||
Barney 37
|
||||
</pre>
|
||||
And the array will be returned with the entries sorted by their numbers.
|
||||
';
|
||||
function ageSorter($req)
|
||||
{
|
||||
global $agesorter_arr, $s;
|
||||
|
||||
PhpXmlRpc\Server::xmlrpc_debugmsg("Entering 'agesorter'");
|
||||
// get the parameter
|
||||
$sno = $req->getParam(0);
|
||||
// error string for [if|when] things go wrong
|
||||
$err = "";
|
||||
$agar = array();
|
||||
|
||||
$max = $sno->count();
|
||||
PhpXmlRpc\Server::xmlrpc_debugmsg("Found $max array elements");
|
||||
foreach ($sno as $i => $rec) {
|
||||
if ($rec->kindOf() != "struct") {
|
||||
$err = "Found non-struct in array at element $i";
|
||||
break;
|
||||
}
|
||||
// extract name and age from struct
|
||||
$n = $rec["name"];
|
||||
$a = $rec["age"];
|
||||
// $n and $a are xmlrpcvals,
|
||||
// so get the scalarval from them
|
||||
$agar[$n->scalarval()] = $a->scalarval();
|
||||
}
|
||||
|
||||
// create the output value
|
||||
$v = new Value(array(), Value::$xmlrpcArray);
|
||||
|
||||
$agesorter_arr = $agar;
|
||||
// hack, must make global as uksort() won't
|
||||
// allow us to pass any other auxiliary information
|
||||
uksort($agesorter_arr, 'agesorter_compare');
|
||||
while (list($key, $val) = each($agesorter_arr)) {
|
||||
// recreate each struct element
|
||||
$v[] = new Value(
|
||||
array(
|
||||
"name" => new Value($key),
|
||||
"age" => new Value($val, "int")
|
||||
),
|
||||
Value::$xmlrpcStruct
|
||||
);
|
||||
}
|
||||
|
||||
if ($err) {
|
||||
return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
|
||||
} else {
|
||||
return new PhpXmlRpc\Response($v);
|
||||
}
|
||||
}
|
||||
|
||||
// signature and instructions, place these in the dispatch map
|
||||
$mailsend_sig = array(array(
|
||||
Value::$xmlrpcBoolean, Value::$xmlrpcString, Value::$xmlrpcString,
|
||||
Value::$xmlrpcString, Value::$xmlrpcString, Value::$xmlrpcString,
|
||||
Value::$xmlrpcString, Value::$xmlrpcString,
|
||||
));
|
||||
$mailsend_doc = 'mail.send(recipient, subject, text, sender, cc, bcc, mimetype)<br/>
|
||||
recipient, cc, and bcc are strings, comma-separated lists of email addresses, as described above.<br/>
|
||||
subject is a string, the subject of the message.<br/>
|
||||
sender is a string, it\'s the email address of the person sending the message. This string can not be
|
||||
a comma-separated list, it must contain a single email address only.<br/>
|
||||
text is a string, it contains the body of the message.<br/>
|
||||
mimetype, a string, is a standard MIME type, for example, text/plain.
|
||||
';
|
||||
// WARNING; this functionality depends on the sendmail -t option
|
||||
// it may not work with Windows machines properly; particularly
|
||||
// the Bcc option. Sneak on your friends at your own risk!
|
||||
function mailSend($req)
|
||||
{
|
||||
$err = "";
|
||||
|
||||
$mTo = $req->getParam(0);
|
||||
$mSub = $req->getParam(1);
|
||||
$mBody = $req->getParam(2);
|
||||
$mFrom = $req->getParam(3);
|
||||
$mCc = $req->getParam(4);
|
||||
$mBcc = $req->getParam(5);
|
||||
$mMime = $req->getParam(6);
|
||||
|
||||
if ($mTo->scalarval() == "") {
|
||||
$err = "Error, no 'To' field specified";
|
||||
}
|
||||
|
||||
if ($mFrom->scalarval() == "") {
|
||||
$err = "Error, no 'From' field specified";
|
||||
}
|
||||
|
||||
$msgHdr = "From: " . $mFrom->scalarval() . "\n";
|
||||
$msgHdr .= "To: " . $mTo->scalarval() . "\n";
|
||||
|
||||
if ($mCc->scalarval() != "") {
|
||||
$msgHdr .= "Cc: " . $mCc->scalarval() . "\n";
|
||||
}
|
||||
if ($mBcc->scalarval() != "") {
|
||||
$msgHdr .= "Bcc: " . $mBcc->scalarval() . "\n";
|
||||
}
|
||||
if ($mMime->scalarval() != "") {
|
||||
$msgHdr .= "Content-type: " . $mMime->scalarval() . "\n";
|
||||
}
|
||||
$msgHdr .= "X-Mailer: XML-RPC for PHP mailer 1.0";
|
||||
|
||||
if ($err == "") {
|
||||
if (!mail("",
|
||||
$mSub->scalarval(),
|
||||
$mBody->scalarval(),
|
||||
$msgHdr)
|
||||
) {
|
||||
$err = "Error, could not send the mail.";
|
||||
}
|
||||
}
|
||||
|
||||
if ($err) {
|
||||
return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
|
||||
} else {
|
||||
return new PhpXmlRpc\Response(new Value(true, Value::$xmlrpcBoolean));
|
||||
}
|
||||
}
|
||||
|
||||
$getallheaders_sig = array(array(Value::$xmlrpcStruct));
|
||||
$getallheaders_doc = 'Returns a struct containing all the HTTP headers received with the request. Provides limited functionality with IIS';
|
||||
function getAllHeaders_xmlrpc($req)
|
||||
{
|
||||
$encoder = new PhpXmlRpc\Encoder();
|
||||
|
||||
if (function_exists('getallheaders')) {
|
||||
return new PhpXmlRpc\Response($encoder->encode(getallheaders()));
|
||||
} else {
|
||||
$headers = array();
|
||||
// IIS: poor man's version of getallheaders
|
||||
foreach ($_SERVER as $key => $val) {
|
||||
if (strpos($key, 'HTTP_') === 0) {
|
||||
$key = ucfirst(str_replace('_', '-', strtolower(substr($key, 5))));
|
||||
$headers[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return new PhpXmlRpc\Response($encoder->encode($headers));
|
||||
}
|
||||
}
|
||||
|
||||
$setcookies_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcStruct));
|
||||
$setcookies_doc = 'Sends to client a response containing a single \'1\' digit, and sets to it http cookies as received in the request (array of structs describing a cookie)';
|
||||
function setCookies($req)
|
||||
{
|
||||
$encoder = new PhpXmlRpc\Encoder();
|
||||
$cookies = $req->getParam(0);
|
||||
foreach ($cookies as $name => $value) {
|
||||
$cookieDesc = $encoder->decode($value);
|
||||
setcookie($name, @$cookieDesc['value'], @$cookieDesc['expires'], @$cookieDesc['path'], @$cookieDesc['domain'], @$cookieDesc['secure']);
|
||||
}
|
||||
|
||||
return new PhpXmlRpc\Response(new Value(1, Value::$xmlrpcInt));
|
||||
}
|
||||
|
||||
$getcookies_sig = array(array(Value::$xmlrpcStruct));
|
||||
$getcookies_doc = 'Sends to client a response containing all http cookies as received in the request (as struct)';
|
||||
function getCookies($req)
|
||||
{
|
||||
$encoder = new PhpXmlRpc\Encoder();
|
||||
return new PhpXmlRpc\Response($encoder->encode($_COOKIE));
|
||||
}
|
||||
|
||||
$v1_arrayOfStructs_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcArray));
|
||||
$v1_arrayOfStructs_doc = 'This handler takes a single parameter, an array of structs, each of which contains at least three elements named moe, larry and curly, all <i4>s. Your handler must add all the struct elements named curly and return the result.';
|
||||
function v1_arrayOfStructs($req)
|
||||
{
|
||||
$sno = $req->getParam(0);
|
||||
$numCurly = 0;
|
||||
foreach ($sno as $str) {
|
||||
foreach ($str as $key => $val) {
|
||||
if ($key == "curly") {
|
||||
$numCurly += $val->scalarval();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new PhpXmlRpc\Response(new Value($numCurly, Value::$xmlrpcInt));
|
||||
}
|
||||
|
||||
$v1_easyStruct_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcStruct));
|
||||
$v1_easyStruct_doc = 'This handler takes a single parameter, a struct, containing at least three elements named moe, larry and curly, all <i4>s. Your handler must add the three numbers and return the result.';
|
||||
function v1_easyStruct($req)
|
||||
{
|
||||
$sno = $req->getParam(0);
|
||||
$moe = $sno["moe"];
|
||||
$larry = $sno["larry"];
|
||||
$curly = $sno["curly"];
|
||||
$num = $moe->scalarval() + $larry->scalarval() + $curly->scalarval();
|
||||
|
||||
return new PhpXmlRpc\Response(new Value($num, Value::$xmlrpcInt));
|
||||
}
|
||||
|
||||
$v1_echoStruct_sig = array(array(Value::$xmlrpcStruct, Value::$xmlrpcStruct));
|
||||
$v1_echoStruct_doc = 'This handler takes a single parameter, a struct. Your handler must return the struct.';
|
||||
function v1_echoStruct($req)
|
||||
{
|
||||
$sno = $req->getParam(0);
|
||||
|
||||
return new PhpXmlRpc\Response($sno);
|
||||
}
|
||||
|
||||
$v1_manyTypes_sig = array(array(
|
||||
Value::$xmlrpcArray, Value::$xmlrpcInt, Value::$xmlrpcBoolean,
|
||||
Value::$xmlrpcString, Value::$xmlrpcDouble, Value::$xmlrpcDateTime,
|
||||
Value::$xmlrpcBase64,
|
||||
));
|
||||
$v1_manyTypes_doc = 'This handler takes six parameters, and returns an array containing all the parameters.';
|
||||
function v1_manyTypes($req)
|
||||
{
|
||||
return new PhpXmlRpc\Response(new Value(
|
||||
array(
|
||||
$req->getParam(0),
|
||||
$req->getParam(1),
|
||||
$req->getParam(2),
|
||||
$req->getParam(3),
|
||||
$req->getParam(4),
|
||||
$req->getParam(5)
|
||||
),
|
||||
Value::$xmlrpcArray
|
||||
));
|
||||
}
|
||||
|
||||
$v1_moderateSizeArrayCheck_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcArray));
|
||||
$v1_moderateSizeArrayCheck_doc = 'This handler takes a single parameter, which is an array containing between 100 and 200 elements. Each of the items is a string, your handler must return a string containing the concatenated text of the first and last elements.';
|
||||
function v1_moderateSizeArrayCheck($req)
|
||||
{
|
||||
$ar = $req->getParam(0);
|
||||
$sz = $ar->count();
|
||||
$first = $ar[0];
|
||||
$last = $ar[$sz - 1];
|
||||
|
||||
return new PhpXmlRpc\Response(new Value($first->scalarval() .
|
||||
$last->scalarval(), Value::$xmlrpcString));
|
||||
}
|
||||
|
||||
$v1_simpleStructReturn_sig = array(array(Value::$xmlrpcStruct, Value::$xmlrpcInt));
|
||||
$v1_simpleStructReturn_doc = 'This handler takes one parameter, and returns a struct containing three elements, times10, times100 and times1000, the result of multiplying the number by 10, 100 and 1000.';
|
||||
function v1_simpleStructReturn($req)
|
||||
{
|
||||
$sno = $req->getParam(0);
|
||||
$v = $sno->scalarval();
|
||||
|
||||
return new PhpXmlRpc\Response(new Value(
|
||||
array(
|
||||
"times10" => new Value($v * 10, Value::$xmlrpcInt),
|
||||
"times100" => new Value($v * 100, Value::$xmlrpcInt),
|
||||
"times1000" => new Value($v * 1000, Value::$xmlrpcInt)
|
||||
),
|
||||
Value::$xmlrpcStruct
|
||||
));
|
||||
}
|
||||
|
||||
$v1_nestedStruct_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcStruct));
|
||||
$v1_nestedStruct_doc = 'This handler takes a single parameter, a struct, that models a daily calendar. At the top level, there is one struct for each year. Each year is broken down into months, and months into days. Most of the days are empty in the struct you receive, but the entry for April 1, 2000 contains a least three elements named moe, larry and curly, all <i4>s. Your handler must add the three numbers and return the result.';
|
||||
function v1_nestedStruct($req)
|
||||
{
|
||||
$sno = $req->getParam(0);
|
||||
|
||||
$twoK = $sno["2000"];
|
||||
$april = $twoK["04"];
|
||||
$fools = $april["01"];
|
||||
$curly = $fools["curly"];
|
||||
$larry = $fools["larry"];
|
||||
$moe = $fools["moe"];
|
||||
|
||||
return new PhpXmlRpc\Response(new Value($curly->scalarval() + $larry->scalarval() + $moe->scalarval(), Value::$xmlrpcInt));
|
||||
}
|
||||
|
||||
$v1_countTheEntities_sig = array(array(Value::$xmlrpcStruct, Value::$xmlrpcString));
|
||||
$v1_countTheEntities_doc = 'This handler takes a single parameter, a string, that contains any number of predefined entities, namely <, >, & \' and ".<BR>Your handler must return a struct that contains five fields, all numbers: ctLeftAngleBrackets, ctRightAngleBrackets, ctAmpersands, ctApostrophes, ctQuotes.';
|
||||
function v1_countTheEntities($req)
|
||||
{
|
||||
$sno = $req->getParam(0);
|
||||
$str = $sno->scalarval();
|
||||
$gt = 0;
|
||||
$lt = 0;
|
||||
$ap = 0;
|
||||
$qu = 0;
|
||||
$amp = 0;
|
||||
for ($i = 0; $i < strlen($str); $i++) {
|
||||
$c = substr($str, $i, 1);
|
||||
switch ($c) {
|
||||
case ">":
|
||||
$gt++;
|
||||
break;
|
||||
case "<":
|
||||
$lt++;
|
||||
break;
|
||||
case "\"":
|
||||
$qu++;
|
||||
break;
|
||||
case "'":
|
||||
$ap++;
|
||||
break;
|
||||
case "&":
|
||||
$amp++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new PhpXmlRpc\Response(new Value(
|
||||
array(
|
||||
"ctLeftAngleBrackets" => new Value($lt, Value::$xmlrpcInt),
|
||||
"ctRightAngleBrackets" => new Value($gt, Value::$xmlrpcInt),
|
||||
"ctAmpersands" => new Value($amp, Value::$xmlrpcInt),
|
||||
"ctApostrophes" => new Value($ap, Value::$xmlrpcInt),
|
||||
"ctQuotes" => new Value($qu, Value::$xmlrpcInt)
|
||||
),
|
||||
Value::$xmlrpcStruct
|
||||
));
|
||||
}
|
||||
|
||||
// trivial interop tests
|
||||
// http://www.xmlrpc.com/stories/storyReader$1636
|
||||
|
||||
$i_echoString_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcString));
|
||||
$i_echoString_doc = "Echoes string.";
|
||||
|
||||
$i_echoStringArray_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
|
||||
$i_echoStringArray_doc = "Echoes string array.";
|
||||
|
||||
$i_echoInteger_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcInt));
|
||||
$i_echoInteger_doc = "Echoes integer.";
|
||||
|
||||
$i_echoIntegerArray_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
|
||||
$i_echoIntegerArray_doc = "Echoes integer array.";
|
||||
|
||||
$i_echoFloat_sig = array(array(Value::$xmlrpcDouble, Value::$xmlrpcDouble));
|
||||
$i_echoFloat_doc = "Echoes float.";
|
||||
|
||||
$i_echoFloatArray_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
|
||||
$i_echoFloatArray_doc = "Echoes float array.";
|
||||
|
||||
$i_echoStruct_sig = array(array(Value::$xmlrpcStruct, Value::$xmlrpcStruct));
|
||||
$i_echoStruct_doc = "Echoes struct.";
|
||||
|
||||
$i_echoStructArray_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
|
||||
$i_echoStructArray_doc = "Echoes struct array.";
|
||||
|
||||
$i_echoValue_doc = "Echoes any value back.";
|
||||
$i_echoValue_sig = array(array(Value::$xmlrpcValue, Value::$xmlrpcValue));
|
||||
|
||||
$i_echoBase64_sig = array(array(Value::$xmlrpcBase64, Value::$xmlrpcBase64));
|
||||
$i_echoBase64_doc = "Echoes base64.";
|
||||
|
||||
$i_echoDate_sig = array(array(Value::$xmlrpcDateTime, Value::$xmlrpcDateTime));
|
||||
$i_echoDate_doc = "Echoes dateTime.";
|
||||
|
||||
function i_echoParam($req)
|
||||
{
|
||||
$s = $req->getParam(0);
|
||||
|
||||
return new PhpXmlRpc\Response($s);
|
||||
}
|
||||
|
||||
function i_echoString($req)
|
||||
{
|
||||
return i_echoParam($req);
|
||||
}
|
||||
|
||||
function i_echoInteger($req)
|
||||
{
|
||||
return i_echoParam($req);
|
||||
}
|
||||
|
||||
function i_echoFloat($req)
|
||||
{
|
||||
return i_echoParam($req);
|
||||
}
|
||||
|
||||
function i_echoStruct($req)
|
||||
{
|
||||
return i_echoParam($req);
|
||||
}
|
||||
|
||||
function i_echoStringArray($req)
|
||||
{
|
||||
return i_echoParam($req);
|
||||
}
|
||||
|
||||
function i_echoIntegerArray($req)
|
||||
{
|
||||
return i_echoParam($req);
|
||||
}
|
||||
|
||||
function i_echoFloatArray($req)
|
||||
{
|
||||
return i_echoParam($req);
|
||||
}
|
||||
|
||||
function i_echoStructArray($req)
|
||||
{
|
||||
return i_echoParam($req);
|
||||
}
|
||||
|
||||
function i_echoValue($req)
|
||||
{
|
||||
return i_echoParam($req);
|
||||
}
|
||||
|
||||
function i_echoBase64($req)
|
||||
{
|
||||
return i_echoParam($req);
|
||||
}
|
||||
|
||||
function i_echoDate($req)
|
||||
{
|
||||
return i_echoParam($req);
|
||||
}
|
||||
|
||||
$i_whichToolkit_sig = array(array(Value::$xmlrpcStruct));
|
||||
$i_whichToolkit_doc = "Returns a struct containing the following strings: toolkitDocsUrl, toolkitName, toolkitVersion, toolkitOperatingSystem.";
|
||||
|
||||
function i_whichToolkit($req)
|
||||
{
|
||||
global $SERVER_SOFTWARE;
|
||||
$ret = array(
|
||||
"toolkitDocsUrl" => "http://phpxmlrpc.sourceforge.net/",
|
||||
"toolkitName" => PhpXmlRpc\PhpXmlRpc::$xmlrpcName,
|
||||
"toolkitVersion" => PhpXmlRpc\PhpXmlRpc::$xmlrpcVersion,
|
||||
"toolkitOperatingSystem" => isset($SERVER_SOFTWARE) ? $SERVER_SOFTWARE : $_SERVER['SERVER_SOFTWARE'],
|
||||
);
|
||||
|
||||
$encoder = new PhpXmlRpc\Encoder();
|
||||
return new PhpXmlRpc\Response($encoder->encode($ret));
|
||||
}
|
||||
|
||||
$object = new xmlrpcServerMethodsContainer();
|
||||
$signatures = array(
|
||||
"examples.getStateName" => array(
|
||||
"function" => "findState",
|
||||
"signature" => $findstate_sig,
|
||||
"docstring" => $findstate_doc,
|
||||
),
|
||||
"examples.sortByAge" => array(
|
||||
"function" => "ageSorter",
|
||||
"signature" => $agesorter_sig,
|
||||
"docstring" => $agesorter_doc,
|
||||
),
|
||||
"examples.addtwo" => array(
|
||||
"function" => "addTwo",
|
||||
"signature" => $addtwo_sig,
|
||||
"docstring" => $addtwo_doc,
|
||||
),
|
||||
"examples.addtwodouble" => array(
|
||||
"function" => "addTwoDouble",
|
||||
"signature" => $addtwodouble_sig,
|
||||
"docstring" => $addtwodouble_doc,
|
||||
),
|
||||
"examples.stringecho" => array(
|
||||
"function" => "stringEcho",
|
||||
"signature" => $stringecho_sig,
|
||||
"docstring" => $stringecho_doc,
|
||||
),
|
||||
"examples.echo" => array(
|
||||
"function" => "echoBack",
|
||||
"signature" => $echoback_sig,
|
||||
"docstring" => $echoback_doc,
|
||||
),
|
||||
"examples.decode64" => array(
|
||||
"function" => "echoSixtyFour",
|
||||
"signature" => $echosixtyfour_sig,
|
||||
"docstring" => $echosixtyfour_doc,
|
||||
),
|
||||
"examples.invertBooleans" => array(
|
||||
"function" => "bitFlipper",
|
||||
"signature" => $bitflipper_sig,
|
||||
"docstring" => $bitflipper_doc,
|
||||
),
|
||||
// signature omitted on purpose
|
||||
"tests.generatePHPWarning" => array(
|
||||
"function" => array($object, "phpWarningGenerator"),
|
||||
),
|
||||
// signature omitted on purpose
|
||||
"tests.raiseException" => array(
|
||||
"function" => array($object, "exceptionGenerator"),
|
||||
),
|
||||
// Greek word 'kosme'. NB: NOT a valid ISO8859 string!
|
||||
// NB: we can only register this when setting internal encoding to UTF-8, or it will break system.listMethods
|
||||
"tests.utf8methodname." . 'κόσμε' => array(
|
||||
"function" => "stringEcho",
|
||||
"signature" => $stringecho_sig,
|
||||
"docstring" => $stringecho_doc,
|
||||
),
|
||||
/*"tests.iso88591methodname." . chr(224) . chr(252) . chr(232) => array(
|
||||
"function" => "stringEcho",
|
||||
"signature" => $stringecho_sig,
|
||||
"docstring" => $stringecho_doc,
|
||||
),*/
|
||||
"examples.getallheaders" => array(
|
||||
"function" => 'getAllHeaders_xmlrpc',
|
||||
"signature" => $getallheaders_sig,
|
||||
"docstring" => $getallheaders_doc,
|
||||
),
|
||||
"examples.setcookies" => array(
|
||||
"function" => 'setCookies',
|
||||
"signature" => $setcookies_sig,
|
||||
"docstring" => $setcookies_doc,
|
||||
),
|
||||
"examples.getcookies" => array(
|
||||
"function" => 'getCookies',
|
||||
"signature" => $getcookies_sig,
|
||||
"docstring" => $getcookies_doc,
|
||||
),
|
||||
"mail.send" => array(
|
||||
"function" => "mailSend",
|
||||
"signature" => $mailsend_sig,
|
||||
"docstring" => $mailsend_doc,
|
||||
),
|
||||
"validator1.arrayOfStructsTest" => array(
|
||||
"function" => "v1_arrayOfStructs",
|
||||
"signature" => $v1_arrayOfStructs_sig,
|
||||
"docstring" => $v1_arrayOfStructs_doc,
|
||||
),
|
||||
"validator1.easyStructTest" => array(
|
||||
"function" => "v1_easyStruct",
|
||||
"signature" => $v1_easyStruct_sig,
|
||||
"docstring" => $v1_easyStruct_doc,
|
||||
),
|
||||
"validator1.echoStructTest" => array(
|
||||
"function" => "v1_echoStruct",
|
||||
"signature" => $v1_echoStruct_sig,
|
||||
"docstring" => $v1_echoStruct_doc,
|
||||
),
|
||||
"validator1.manyTypesTest" => array(
|
||||
"function" => "v1_manyTypes",
|
||||
"signature" => $v1_manyTypes_sig,
|
||||
"docstring" => $v1_manyTypes_doc,
|
||||
),
|
||||
"validator1.moderateSizeArrayCheck" => array(
|
||||
"function" => "v1_moderateSizeArrayCheck",
|
||||
"signature" => $v1_moderateSizeArrayCheck_sig,
|
||||
"docstring" => $v1_moderateSizeArrayCheck_doc,
|
||||
),
|
||||
"validator1.simpleStructReturnTest" => array(
|
||||
"function" => "v1_simpleStructReturn",
|
||||
"signature" => $v1_simpleStructReturn_sig,
|
||||
"docstring" => $v1_simpleStructReturn_doc,
|
||||
),
|
||||
"validator1.nestedStructTest" => array(
|
||||
"function" => "v1_nestedStruct",
|
||||
"signature" => $v1_nestedStruct_sig,
|
||||
"docstring" => $v1_nestedStruct_doc,
|
||||
),
|
||||
"validator1.countTheEntities" => array(
|
||||
"function" => "v1_countTheEntities",
|
||||
"signature" => $v1_countTheEntities_sig,
|
||||
"docstring" => $v1_countTheEntities_doc,
|
||||
),
|
||||
"interopEchoTests.echoString" => array(
|
||||
"function" => "i_echoString",
|
||||
"signature" => $i_echoString_sig,
|
||||
"docstring" => $i_echoString_doc,
|
||||
),
|
||||
"interopEchoTests.echoStringArray" => array(
|
||||
"function" => "i_echoStringArray",
|
||||
"signature" => $i_echoStringArray_sig,
|
||||
"docstring" => $i_echoStringArray_doc,
|
||||
),
|
||||
"interopEchoTests.echoInteger" => array(
|
||||
"function" => "i_echoInteger",
|
||||
"signature" => $i_echoInteger_sig,
|
||||
"docstring" => $i_echoInteger_doc,
|
||||
),
|
||||
"interopEchoTests.echoIntegerArray" => array(
|
||||
"function" => "i_echoIntegerArray",
|
||||
"signature" => $i_echoIntegerArray_sig,
|
||||
"docstring" => $i_echoIntegerArray_doc,
|
||||
),
|
||||
"interopEchoTests.echoFloat" => array(
|
||||
"function" => "i_echoFloat",
|
||||
"signature" => $i_echoFloat_sig,
|
||||
"docstring" => $i_echoFloat_doc,
|
||||
),
|
||||
"interopEchoTests.echoFloatArray" => array(
|
||||
"function" => "i_echoFloatArray",
|
||||
"signature" => $i_echoFloatArray_sig,
|
||||
"docstring" => $i_echoFloatArray_doc,
|
||||
),
|
||||
"interopEchoTests.echoStruct" => array(
|
||||
"function" => "i_echoStruct",
|
||||
"signature" => $i_echoStruct_sig,
|
||||
"docstring" => $i_echoStruct_doc,
|
||||
),
|
||||
"interopEchoTests.echoStructArray" => array(
|
||||
"function" => "i_echoStructArray",
|
||||
"signature" => $i_echoStructArray_sig,
|
||||
"docstring" => $i_echoStructArray_doc,
|
||||
),
|
||||
"interopEchoTests.echoValue" => array(
|
||||
"function" => "i_echoValue",
|
||||
"signature" => $i_echoValue_sig,
|
||||
"docstring" => $i_echoValue_doc,
|
||||
),
|
||||
"interopEchoTests.echoBase64" => array(
|
||||
"function" => "i_echoBase64",
|
||||
"signature" => $i_echoBase64_sig,
|
||||
"docstring" => $i_echoBase64_doc,
|
||||
),
|
||||
"interopEchoTests.echoDate" => array(
|
||||
"function" => "i_echoDate",
|
||||
"signature" => $i_echoDate_sig,
|
||||
"docstring" => $i_echoDate_doc,
|
||||
),
|
||||
"interopEchoTests.whichToolkit" => array(
|
||||
"function" => "i_whichToolkit",
|
||||
"signature" => $i_whichToolkit_sig,
|
||||
"docstring" => $i_whichToolkit_doc,
|
||||
),
|
||||
|
||||
'tests.getStateName.2' => $findstate2_sig,
|
||||
'tests.getStateName.3' => $findstate3_sig,
|
||||
'tests.getStateName.4' => $findstate4_sig,
|
||||
'tests.getStateName.5' => $findstate5_sig,
|
||||
'tests.getStateName.6' => $findstate6_sig,
|
||||
'tests.getStateName.7' => $findstate7_sig,
|
||||
'tests.getStateName.8' => $findstate8_sig,
|
||||
'tests.getStateName.9' => $findstate9_sig,
|
||||
'tests.getStateName.10' => $findstate10_sig,
|
||||
'tests.getStateName.11' => $findstate11_sig,
|
||||
|
||||
'tests.getStateName.12' => array(
|
||||
"function" => "findStateWithNulls",
|
||||
"signature" => $findstate12_sig,
|
||||
"docstring" => $findstate_doc,
|
||||
),
|
||||
|
||||
'tests.returnPhpObject' => $returnObj_sig,
|
||||
);
|
||||
|
||||
$signatures = array_merge($signatures, $moreSignatures);
|
||||
|
||||
// enable support for the NULL extension
|
||||
PhpXmlRpc\PhpXmlRpc::$xmlrpc_null_extension = true;
|
||||
|
||||
$s = new PhpXmlRpc\Server($signatures, false);
|
||||
$s->setdebug(3);
|
||||
$s->compress_response = true;
|
||||
|
||||
// out-of-band information: let the client manipulate the server operations.
|
||||
// we do this to help the testsuite script: do not reproduce in production!
|
||||
if (isset($_GET['RESPONSE_ENCODING'])) {
|
||||
$s->response_charset_encoding = $_GET['RESPONSE_ENCODING'];
|
||||
}
|
||||
if (isset($_GET['DETECT_ENCODINGS'])) {
|
||||
PhpXmlRpc\PhpXmlRpc::$xmlrpc_detectencodings = $_GET['DETECT_ENCODINGS'];
|
||||
}
|
||||
if (isset($_GET['EXCEPTION_HANDLING'])) {
|
||||
$s->exception_handling = $_GET['EXCEPTION_HANDLING'];
|
||||
}
|
||||
$s->service();
|
||||
// that should do all we need!
|
||||
|
||||
// out-of-band information: let the client manipulate the server operations.
|
||||
// we do this to help the testsuite script: do not reproduce in production!
|
||||
if (isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) && extension_loaded('xdebug')) {
|
||||
include_once __DIR__ . "/../../vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumCommon/append.php";
|
||||
}
|
||||
95
lib/phpxmlrpc/demo/vardemo.php
Normal file
95
lib/phpxmlrpc/demo/vardemo.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<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,
|
||||
Whose fleece was white as snow,
|
||||
And everywhere that Mary went
|
||||
the lamb was sure to go.
|
||||
|
||||
Mary had a little lamb
|
||||
She tied it to a pylon
|
||||
Ten thousand volts went down its back
|
||||
And 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);
|
||||
print "That is to say $date --> $tb\n";
|
||||
print "Which comes out at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb) . "\n";
|
||||
print "Which was the time in UTC at " . PhpXmlRpc\Helper\Date::iso8601Encode($date, 1) . "\n";
|
||||
|
||||
print "</pre>\n";
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user