3 * Demo server for xmlrpc library.
5 * Implements a lot of webservices, including a suite of services used for interoperability testing (validator1 methods),
6 * and some whose only purpose is to be used for unit-testing the library.
8 * Please _do not_ copy this file verbatim into your production server.
11 require_once __DIR__ . "/_prepend.php";
13 use PhpXmlRpc\PhpXmlRpc;
14 use PhpXmlRpc\Response;
18 // Most of the code used to implement the webservices, and their signatures, are stowed away in neatly organized
19 // files, each demoing a different topic
21 // The simplest way of implementing webservices: as xmlrpc-aware global functions
22 $signatures1 = include(__DIR__.'/methodProviders/functions.php');
24 // Examples of exposing as webservices php functions and objects/methods which are not aware of xmlrpc classes
25 $signatures2 = include(__DIR__.'/methodProviders/wrapper.php');
27 // Definitions of webservices used for interoperability testing
28 $signatures3 = include(__DIR__.'/methodProviders/interop.php');
29 $signatures4 = include(__DIR__.'/methodProviders/validator1.php');
31 // And finally a few examples inline
33 // used to test signatures with NULL params
34 $findstate12_sig = array(
35 array(Value::$xmlrpcString, Value::$xmlrpcInt, Value::$xmlrpcNull),
36 array(Value::$xmlrpcString, Value::$xmlrpcNull, Value::$xmlrpcInt),
38 function findStateWithNulls($req)
40 $a = $req->getParam(0);
41 $b = $req->getParam(1);
43 if ($a->scalartyp() == Value::$xmlrpcNull)
44 return new Response(new Value(plain_findstate($b->scalarval())));
46 return new Response(new Value(plain_findstate($a->scalarval())));
49 $object = new xmlrpcServerMethodsContainer();
53 // signature omitted on purpose
54 "tests.generatePHPWarning" => array(
55 "function" => array($object, "phpWarningGenerator"),
57 // signature omitted on purpose
58 "tests.raiseException" => array(
59 "function" => array($object, "exceptionGenerator"),
61 // Greek word 'kosme'. NB: NOT a valid ISO8859 string!
62 // NB: we can only register this when setting internal encoding to UTF-8, or it will break system.listMethods
63 "tests.utf8methodname." . 'κόσμε' => array(
64 "function" => "stringEcho",
65 "signature" => $stringecho_sig,
66 "docstring" => $stringecho_doc,
68 /*"tests.iso88591methodname." . chr(224) . chr(252) . chr(232) => array(
69 "function" => "stringEcho",
70 "signature" => $stringecho_sig,
71 "docstring" => $stringecho_doc,
74 'tests.getStateName.12' => array(
75 "function" => "findStateWithNulls",
76 "signature" => $findstate12_sig,
77 "docstring" => $findstate_doc,
81 $signatures = array_merge($signatures, $signatures1, $signatures2, $signatures3, $signatures4);
83 // Enable support for the NULL extension
84 PhpXmlRpc::$xmlrpc_null_extension = true;
86 $s = new Server($signatures, false);
88 $s->compress_response = true;
90 // Out-of-band information: let the client manipulate the server operations.
91 // We do this to help the testsuite script: do not reproduce in production!
92 if (isset($_GET['RESPONSE_ENCODING'])) {
93 $s->response_charset_encoding = $_GET['RESPONSE_ENCODING'];
95 if (isset($_GET['DETECT_ENCODINGS'])) {
96 PhpXmlRpc::$xmlrpc_detectencodings = $_GET['DETECT_ENCODINGS'];
98 if (isset($_GET['EXCEPTION_HANDLING'])) {
99 $s->exception_handling = $_GET['EXCEPTION_HANDLING'];
101 if (isset($_GET['FORCE_AUTH'])) {
102 // We implement both Basic and Digest auth in php to avoid having to set it up in a vhost.
103 // Code taken from php.net
104 // NB: we do NOT check for valid credentials!
105 if ($_GET['FORCE_AUTH'] == 'Basic') {
106 if (!isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['REMOTE_USER']) && !isset($_SERVER['REDIRECT_REMOTE_USER'])) {
107 header('HTTP/1.0 401 Unauthorized');
108 header('WWW-Authenticate: Basic realm="Phpxmlrpc Basic Realm"');
109 die('Text visible if user hits Cancel button');
111 } elseif ($_GET['FORCE_AUTH'] == 'Digest') {
112 if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
113 header('HTTP/1.1 401 Unauthorized');
114 header('WWW-Authenticate: Digest realm="Phpxmlrpc Digest Realm",qop="auth",nonce="'.uniqid().'",opaque="'.md5('Phpxmlrpc Digest Realm').'"');
115 die('Text visible if user hits Cancel button');
121 // That should do all we need!
123 require_once __DIR__ . "/_append.php";