return new Response($rv);
}
-$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 Encoder();
-
- if (function_exists('getallheaders')) {
- return new 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 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 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 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 Encoder();
- return new Response($encoder->encode($_COOKIE));
-}
$mailsend_sig = array(array(
Value::$xmlrpcBoolean, Value::$xmlrpcString, Value::$xmlrpcString,
"docstring" => $bitflipper_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(
+ // left in as an example, but disabled by default, to avoid this being abused if left on an open server
+ /*"mail.send" => array(
"function" => "mailSend",
"signature" => $mailsend_sig,
"docstring" => $mailsend_doc,
- ),
+ ),*/
);
--- /dev/null
+<?php
+/**
+ * Defines functions and signatures which can be registered as methods exposed by an XMLRPC Server.
+ *
+ * To use this, use something akin to:
+ * $signatures = include('tests.php');
+ *
+ * Methods used by the xmlrpc testsuite
+ */
+
+use PhpXmlRpc\Encoder;
+use PhpXmlRpc\Response;
+use PhpXmlRpc\Value;
+
+$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 Encoder();
+
+ if (function_exists('getallheaders')) {
+ return new Response($encoder->encode(getallheaders()));
+ } else {
+ $headers = array();
+ // 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 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 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 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 Encoder();
+ return new Response($encoder->encode($_COOKIE));
+}
+
+// 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 Response(new Value(plain_findstate($b->scalarval())));
+ else
+ return new Response(new Value(plain_findstate($a->scalarval())));
+}
+
+return array(
+ "tests.getallheaders" => array(
+ "function" => 'getAllHeaders_xmlrpc',
+ "signature" => $getallheaders_sig,
+ "docstring" => $getallheaders_doc,
+ ),
+ "tests.setcookies" => array(
+ "function" => 'setCookies',
+ "signature" => $setcookies_sig,
+ "docstring" => $setcookies_doc,
+ ),
+ "tests.getcookies" => array(
+ "function" => 'getCookies',
+ "signature" => $getcookies_sig,
+ "docstring" => $getcookies_doc,
+ ),
+
+ // 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,
+ ),*/
+
+ 'tests.getStateName.12' => array(
+ "function" => "findStateWithNulls",
+ "signature" => $findstate12_sig,
+ //"docstring" => $findstate_doc,
+ ),
+);
*
* To use this, use something akin to:
* $signatures = include('wrapper.php');
+ * NB: requires 'functions.php' to be included first
*
* Wrap methods of xmlrpc-unaware php classes and xmlrpc-unaware php functions so that they can be used transparently.
*/
*/
public function phpWarningGenerator($req)
{
+ /** @noinspection PhpUndefinedVariableInspection */
$a = $undefinedVariable; // this triggers a warning in E_ALL mode, since $undefinedVariable is undefined
return new Response(new Value(1, Value::$xmlrpcBoolean));
}
$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']);
eval($findstate9_sig['source']);
$findstate10_sig = array(
- /// @todo add a demo/test with a closure
+ /// @todo add a demo and test with closure usage
"function" => function ($req) { return findState($req); },
"signature" => array(array(Value::$xmlrpcString, Value::$xmlrpcInt)),
"docstring" => 'When passed an integer between 1 and 51 returns the name of a US state, where the integer is the ' .
return array_merge(
array(
'tests.getStateName.2' => $findstate2_sig,
+
'tests.getStateName.3' => $findstate3_sig,
'tests.getStateName.4' => $findstate4_sig,
'tests.getStateName.5' => $findstate5_sig,
'tests.getStateName.9' => $findstate9_sig,
'tests.getStateName.10' => $findstate10_sig,
'tests.getStateName.11' => $findstate11_sig,
- 'tests.returnPhpObject' => $returnObj_sig,
),
+ $moreSignatures,
$namespaceSignatures,
- $moreSignatures
+ array(
+ 'tests.returnPhpObject' => $returnObj_sig,
+ // signature omitted on purpose
+ "tests.generatePHPWarning" => array(
+ "function" => array($obj, "phpWarningGenerator"),
+ ),
+ // signature omitted on purpose
+ "tests.raiseException" => array(
+ "function" => array($obj, "exceptionGenerator"),
+ ),
+ )
);
// The simplest way of implementing webservices: as xmlrpc-aware global functions
$signatures1 = include(__DIR__.'/methodProviders/functions.php');
-// Examples of exposing as webservices php functions and objects/methods which are not aware of xmlrpc classes
-$signatures2 = include(__DIR__.'/methodProviders/wrapper.php');
-
// Definitions of webservices used for interoperability testing
-$signatures3 = include(__DIR__.'/methodProviders/interop.php');
-$signatures4 = include(__DIR__.'/methodProviders/validator1.php');
+$signatures2 = include(__DIR__.'/methodProviders/interop.php');
+$signatures3 = include(__DIR__.'/methodProviders/validator1.php');
// And finally a few examples inline
+$signatures = array();
-// 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 Response(new Value(plain_findstate($b->scalarval())));
- else
- return new Response(new Value(plain_findstate($a->scalarval())));
-}
-
-$object = new xmlrpcServerMethodsContainer();
+$signatures = array_merge($signatures, $signatures1, $signatures2, $signatures3);
-$signatures = array(
-
- // 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,
- ),*/
-
- 'tests.getStateName.12' => array(
- "function" => "findStateWithNulls",
- "signature" => $findstate12_sig,
- "docstring" => $findstate_doc,
- ),
-);
+if (defined('TESTMODE')) {
+ // Webservices used only by the testuite
+ $signatures4 = include(__DIR__.'/methodProviders/testsuite.php');
+ $signatures5 = include(__DIR__.'/methodProviders/wrapper.php');
-$signatures = array_merge($signatures, $signatures1, $signatures2, $signatures3, $signatures4);
+ $signatures = array_merge($signatures, $signatures4, $signatures5);
+}
// Enable support for the NULL extension
PhpXmlRpc::$xmlrpc_null_extension = true;
$this->client->port = $server[1];
}
$this->client->server = $server[0];
- $this->client->path = str_replace('/demo/server/server.php', '/tests/index.php?demo=server/server.php', $this->args['HTTPURI']);
+ //$this->client->path = str_replace('/demo/server/server.php', '/tests/index.php?demo=server/server.php', $this->args['HTTPURI']);
+ $this->client->path = $this->args['HTTPURI'];
$r = $this->client->send($m, 5, 'http11');
$this->assertEquals(0, $r->faultCode());
{
$this->args = argParser::getArgs();
- $uri = str_replace('/demo/server/server.php', '/tests/index.php?demo=server/server.php', $this->args['HTTPURI']);
+ //$uri = str_replace('/demo/server/server.php', '/tests/index.php?demo=server/server.php', $this->args['HTTPURI']);
$server = explode(':', $this->args['HTTPSERVER']);
if (count($server) > 1) {
- $this->client = new xmlrpc_client($uri, $server[0], $server[1]);
+ $this->client = new xmlrpc_client($this->args['HTTPURI'], $server[0], $server[1]);
} else {
- $this->client = new xmlrpc_client($uri, $this->args['HTTPSERVER']);
+ $this->client = new xmlrpc_client($this->args['HTTPURI'], $this->args['HTTPSERVER']);
}
$this->client->setDebug($this->args['DEBUG']);
$this->client->request_compression = $this->request_compression;
$this->client->accepted_compression = $this->accepted_compression;
- $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . '/' . str_replace('/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['HTTPURI']);
+ $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
if ($this->args['DEBUG'] == 1)
ob_start();
'c5' => array('value' => 'c5', 'expires' => time() + 60 * 60 * 24 * 30, 'path' => '/', 'domain' => 'localhost'),
);
$cookiesval = php_xmlrpc_encode($cookies);
- $m = new xmlrpcmsg('examples.setcookies', array($cookiesval));
+ $m = new xmlrpcmsg('tests.setcookies', array($cookiesval));
$r = $this->send($m, 0, true);
if ($r) {
$v = $r->value();
'c2' => '2 3',
'c3' => '!@#$%^&*()_+|}{":?><,./\';[]\\=-',
);
- $m = new xmlrpcmsg('examples.getcookies', array());
+ $m = new xmlrpcmsg('tests.getcookies', array());
foreach ($cookies as $cookie => $val) {
$this->client->setCookie($cookie, $val);
$cookies[$cookie] = (string)$cookies[$cookie];
{
$this->args = argParser::getArgs();
- $this->baseUrl = $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/tests/index.php', $this->args['HTTPURI'] );
-
- $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/tests/phpunit_coverage.php', $this->args['HTTPURI'] );
+ // assumes HTTPURI to be in the form /tests/index.php?etc...
+ $this->baseUrl = $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
+ $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
}
public function testAgeSort()
{
$this->args = argParser::getArgs();
- $this->baseUrl = $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/tests/index.php', $this->args['HTTPURI'] );
-
- $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/tests/phpunit_coverage.php', $this->args['HTTPURI'] );
+ // assumes HTTPURI to be in the form /tests/index.php?etc...
+ $this->baseUrl = $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
+ $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
}
public function testIndex()
{
$this->args = argParser::getArgs();
- $this->baseUrl = $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/tests/index.php', $this->args['HTTPURI'] );
-
- $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/tests/phpunit_coverage.php', $this->args['HTTPURI'] );
+ // assumes HTTPURI to be in the form /tests/index.php?etc...
+ $this->baseUrl = $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
+ $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
}
public function testBenchmark()
--env CONTAINER_USER_UID=$(id -u) --env CONTAINER_USER_GID=$(id -g) \
--env TESTS_ROOT_DIR=${CONTAINER_WORKSPACE_DIR} \
--env HTTPSERVER=localhost \
- --env HTTPURI=/demo/server/server.php \
+ --env HTTPURI=/tests/index.php?demo=server/server.php \
--env HTTPSSERVER=localhost \
- --env HTTPSURI=/demo/server/server.php \
+ --env HTTPSURI=/tests/index.php?demo=server/server.php \
--env PROXYSERVER=localhost:8080 \
--env HTTPSVERIFYHOST=0 \
--env HTTPSIGNOREPEER=1 \
}
if (!isset($HTTPURI) || $HTTPURI == '') {
- // GUESTIMATE the url of local demo server
- // play nice to php 4 and 5 in retrieving URL of server.php
+ // GUESTIMATE the url of local test controller
+ // play nice to php 5 and 7 in retrieving URL of index.php
/// @todo filter out query string from REQUEST_URI
/// @todo review this code...
- if (isset($REQUEST_URI)) {
+ /*if (isset($REQUEST_URI)) {
$HTTPURI = str_replace('/tests/testsuite.php', '/demo/server/server.php', $REQUEST_URI);
$HTTPURI = str_replace('/testsuite.php', '/server.php', $HTTPURI);
$HTTPURI = str_replace('/extras/benchmark.php', '/demo/server/server.php', $HTTPURI);
$HTTPURI = str_replace('/testsuite.php', '/server.php', $HTTPURI);
$HTTPURI = str_replace('/extras/benchmark.php', '/demo/server/server.php', $HTTPURI);
$HTTPURI = str_replace('/benchmark.php', '/server.php', $HTTPURI);
- } else {
- $HTTPURI = '/demo/server/server.php';
- }
+ } else {*/
+ $HTTPURI = '/tests/index.php?demo=server/server.php';
+ //}
}
if ($HTTPURI[0] != '/') {
$HTTPURI = '/' . $HTTPURI;