From: gggeek Date: Tue, 17 Jan 2023 12:07:38 +0000 (+0000) Subject: demo nitpicks X-Git-Tag: 4.10.0~150 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=dabedcd5f947e17f65ee401f6c2eb1b0579a64fb;p=plcapi.git demo nitpicks --- diff --git a/demo/client/windowscharset.php b/demo/client/windowscharset.php new file mode 100644 index 00000000..c785cd77 --- /dev/null +++ b/demo/client/windowscharset.php @@ -0,0 +1,45 @@ +setDebug(2); +// tell the server not to compress the response +$c->accepted_compression = array(); +// tell the server not to encode everything as ASCII - this is not necessary btw. It is only done to make the demo nicer +$c->accepted_charset_encodings = array('UTF-8'); +// force the client not to encode everything as ASCII - this is not necessary btw. It is only done to make the demo nicer +$c->request_charset_encoding = 'UTF-8'; + +$r = $c->send(new Request('examples.stringecho', array(new Value($input)))); +$output = $r->value()->scalarval(); + +echo "This is the value we got back from the server (in CP-1252): "; +var_dump($output); + +echo "In UTF-8, it looks like this: "; +var_dump(mb_convert_encoding($output, 'UTF-8', 'Windows-1252')); diff --git a/demo/client/wrap.php b/demo/client/wrap.php index aaf7b70a..beb271d1 100644 --- a/demo/client/wrap.php +++ b/demo/client/wrap.php @@ -11,7 +11,7 @@ output('

The code demonstrates usage of some of the most automagic client usage possible:
1) client that returns php values instead of xml-rpc Value objects
2) wrapping of remote methods into php functions
- See also proxy.php for an alternative take + See also proxy.php and codegen.php for alternative takes

You can see the source to this page here: wrap.php

'); diff --git a/demo/server/discuss.php b/demo/server/discuss.php index b31dc3c9..3288c099 100644 --- a/demo/server/discuss.php +++ b/demo/server/discuss.php @@ -27,7 +27,9 @@ $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.'; -$srv = new Server(array( +$srv = new Server(); + +$srv->setDispatchMap(array( "discuss.addComment" => array( "function" => array($manager, "addComment"), "signature" => $addComment_sig, @@ -38,9 +40,9 @@ $srv = new Server(array( "signature" => $getComments_sig, "docstring" => $getComments_doc, ), -), false); +)); -// let the xml=rpc server know that the method-handler functions expect plain php values +// let the xml-rpc server know that the method-handler functions expect plain php values $srv->functions_parameters_type = 'phpvals'; // let code exceptions float all the way to the remote caller as xml-rpc faults - it helps debugging diff --git a/demo/server/methodProviders/functions.php b/demo/server/methodProviders/functions.php index 58444e0f..2949034a 100644 --- a/demo/server/methodProviders/functions.php +++ b/demo/server/methodProviders/functions.php @@ -21,6 +21,7 @@ */ use PhpXmlRpc\Encoder; +use PhpXmlRpc\PhpXmlRpc; use PhpXmlRpc\Response; use PhpXmlRpc\Server; use PhpXmlRpc\Value; @@ -62,7 +63,7 @@ class exampleMethods if ($err != '') { // if we generated an error, create an error return response - return new Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err); + return new Response(0, PhpXmlRpc::$xmlrpcerruser, $err); } else { // otherwise, we create the right response with the state name return new Response(new Value($stateName)); @@ -108,7 +109,7 @@ And the array will be returned with the entries sorted by their numbers.'; if ($err != '') { Server::xmlrpc_debugmsg("Aborting 'agesorter'"); - return new Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err); + return new Response(0, PhpXmlRpc::$xmlrpcerruser, $err); } asort($agar); @@ -156,8 +157,15 @@ And the array will be returned with the entries sorted by their numbers.'; public static $echoback_doc = 'Accepts a string parameter, returns the entire incoming payload'; public static function echoBack($req) { - // just sends back a string with what I got sent to me, that's all (escaping for xml is automatic) - $s = "I got the following message:\n" . $req->serialize(); + // just sends back a string with what I got sent to me, that's all + + /// @todo file_get_contents does not take into account either receiving compressed requests, or requests with + /// data which is not in UTF-8. Otoh using req->serialize means that what we are sending back is not + /// byte-for-byte identical to what we received, and that <, >, ', " and & will be double-encoded. + /// In fact, we miss some API (or extra data) in the Request... + //$payload = file_get_contents('php://input'); + $payload = $req->serialize(PhpXmlRpc::$xmlrpc_internalencoding); + $s = "I got the following message:\n" . $payload; return new Response(new Value($s)); } @@ -251,7 +259,7 @@ mimetype, a string, is a standard MIME type, for example, text/plain.'; } if ($err) { - return new Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err); + return new Response(0, PhpXmlRpc::$xmlrpcerruser, $err); } else { return new Response(new Value(true, Value::$xmlrpcBoolean)); } diff --git a/demo/server/proxy.php b/demo/server/proxy.php index 95b4390f..30cc3177 100644 --- a/demo/server/proxy.php +++ b/demo/server/proxy.php @@ -47,17 +47,35 @@ function forward_request($req) $client = new Client($url); if ($req->getNumParams() > 3) { - // we have to set some options onto the client. + // 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': + case 'authType': + /// @todo add support for this if needed + break; + case 'followRedirects': + // requires cURL to be enabled + if ($val) { + $client->use_curl = Client::USE_CURL_ALWAYS; + $client->setCurlOptions(array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_POSTREDIR => 3)); + } + case 'Cookies': /// @todo add support for this if needed break; case 'Credentials': /// @todo add support for this as well if needed break; + case 'HTTPProxy': + case 'HTTPProxyCredentials': + /// @todo add support for this as well if needed + break; + case 'RequestCharsetEncoding': + // allow the server to work as charset transcoder. + // NB: works best with mbstring enabled + $client->request_charset_encoding = $val; + break; case 'RequestCompression': $client->setRequestCompression($val); break; diff --git a/demo/vardemo.php b/demo/vardemo.php index 22c54295..d693d760 100644 --- a/demo/vardemo.php +++ b/demo/vardemo.php @@ -89,6 +89,9 @@ output("

Testing value serialization - character encoding

\n"); $v = new PhpXmlRpc\Value('κόσμε'); output("Greek (default encoding):
" . htmlentities($v->serialize()) . "
"); output("Greek (utf8 encoding):
" . htmlentities($v->serialize('UTF-8')) . "
"); +if (function_exists('mb_convert_encoding')) { + output("Greek (ISO-8859-7 encoding):
" . htmlentities($v->serialize('ISO-8859-7')) . "
"); +} output("

Testing request serialization

\n"); $req = new PhpXmlRpc\Request('examples.getStateName');