From 91e5d3f4927edd45dcbab802c05e09e3c51b56f4 Mon Sep 17 00:00:00 2001 From: gggeek Date: Mon, 23 Jan 2023 09:23:55 +0000 Subject: [PATCH] news --- NEWS.md | 2 ++ demo/client/codegen.php | 1 + demo/server/codegen.php | 1 + doc/manual/phpxmlrpc_manual.adoc | 29 ++++++++++++++++++++++------- src/Encoder.php | 5 ++++- src/PhpXmlRpc.php | 5 +++-- 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/NEWS.md b/NEWS.md index 02d949eb..7c833f60 100644 --- a/NEWS.md +++ b/NEWS.md @@ -37,6 +37,8 @@ a method handler in the dispatch was defined with `'parameters_type' = 'phpvals'`, the handler would be passed a Request object instead of plain php values. +* fixed: receiving integers which use the '' xml tag + * new: added the `Client::setTimeout` method, meant to replace usage of the `$timeout` argument in calls to `send` and `multicall` diff --git a/demo/client/codegen.php b/demo/client/codegen.php index 672bfa11..d4842bca 100644 --- a/demo/client/codegen.php +++ b/demo/client/codegen.php @@ -19,6 +19,7 @@ $code = $w->wrapXmlrpcServer( 'new_class_name' => 'MyClient', 'method_filter' => '/^examples\./', 'simple_client_copy' => true, + // this is used to encode php NULL values into xml-rpc elements. If the partner does not support that, disable it 'encode_nulls' => true, 'throw_on_fault' => true, ) diff --git a/demo/server/codegen.php b/demo/server/codegen.php index db06d157..c76d3015 100644 --- a/demo/server/codegen.php +++ b/demo/server/codegen.php @@ -13,6 +13,7 @@ $code = $w->wrapPhpClass( array( 'method_type' => 'nonstatic', 'return_source' => true, + // this is used to encode php NULL values into xml-rpc elements. If the partner does not support that, disable it 'encode_nulls' => true, ) ); diff --git a/doc/manual/phpxmlrpc_manual.adoc b/doc/manual/phpxmlrpc_manual.adoc index 20bb60fe..1e6ed30f 100644 --- a/doc/manual/phpxmlrpc_manual.adoc +++ b/doc/manual/phpxmlrpc_manual.adoc @@ -251,6 +251,16 @@ for `PhpXmlRpc\Encoder::decode` for the full details of the decoding process. ==== Notes on types +==== strict parsing vs. lenient parsing + +When Value objects are created by the library by parsing some received XML text, the parsing code is lenient with invalid +data. This means that if the other party is sending some junk, the library will, by default: +- log error messages pinpointing the exact source of the problem, and +- feed to your application "error values", which include `false` for bad base64 data, the string 'ERROR_NON_NUMERIC_FOUND' + for integers and doubles, `false` for invalid booleans and the received string for invalid datetimes. +This behaviour can be changed to make the parsing code more strict and produce an error instead of letting through invalid +data, by setting `PhpXmlRpc\PhpXmlRpc::$xmlrpc_return_datetimes = true`. + ===== base64 Base 64 encoding is performed transparently to the caller when using this type. Decoding is also transparent. @@ -259,12 +269,13 @@ Therefore, you ought to consider it as a "binary" data type, for use when you wa ===== boolean All php values which would be converted to a boolean TRUE via typecasting are mapped to an xml-rpc `true`. All other -values (including the empty string) are converted to `false`. +values (including the empty string) are converted to an xml-rpc `false`. -===== dateTime +===== dateTime.iso8601 -When manually creating Value objects representing an xml-rpc dateTime.iso8601, php integers, strings and DateTimes can be -used as source values. For those, the original value will be returned when calling `+$value->scalarval();+`. +When manually creating Value objects representing an xml-rpc dateTime.iso8601, php DateTimes, integers (unix timestamps) +and strings (representing dates in the specific xml-rpc ISO-8601 format) can be used as source values. For those, the +original value will be returned when calling `+$value->scalarval();+`. When Value objects are created by the library by parsing some received XML text, all Value objects representing an xml-rpc dateTime.iso8601 value will by default return the string representation of the date when calling `+$value->scalarval();+`. @@ -274,10 +285,14 @@ of timezone specifiers in ISO8601 format dates. You can, however, use multiple t into another representation of a time stamp, and take care of timezones by yourself: * use the `PhpXmlRpc\Helper\Date` class to convert the date string into a unix timestamp; * set `PhpXmlRpc\PhpXmlRpc::$xmlrpc_return_datetimes = true` to always get back a php DateTime from received xml (in - which case the conversion is done using the timezone set in php.ini). + which case the conversion is done using the timezone set in php.ini) * use the `PhpXmlRpc\Encoder::decode` method with the 'dates_as_objects' option to get back a php DateTime from a - single Value object (in which case the conversion is done using the `strtotime` function, which uses the timezone set - in php.ini). + single or nested Value object (in which case the conversion is done using the `strtotime` function, which uses the + timezone set in php.ini). +Note that, when using `$xmlrpc_return_datetimes` or 'dates_as_objects', you might still get back a php `false` or `null` +instead of a DateTime if the data received via xml does not represent a valid date and time. You can configure the library +to outright reject such cases and avoid having to explicitly check for them in your own code, by setting +`PhpXmlRpc\PhpXmlRpc::$xmlrpc_return_datetimes = true`. ===== double diff --git a/src/Encoder.php b/src/Encoder.php index 72277005..03fabed9 100644 --- a/src/Encoder.php +++ b/src/Encoder.php @@ -118,11 +118,14 @@ class Encoder } } if (in_array('dates_as_objects', $options) && $xmlrpcVal->scalartyp() == 'dateTime.iso8601') { - // we return a Datetime object instead of a string since now the constructor of xml-rpc value accepts + // we return a Datetime object instead of a string; since now the constructor of xml-rpc value accepts // safely string, int and DateTimeInterface, we cater to all 3 cases here $out = $xmlrpcVal->scalarval(); if (is_string($out)) { $out = strtotime($out); + // NB: if the string does not convert into a timestamp, this will return false. + // We avoid logging an error here, as we presume it was already done when parsing the xml + /// @todo we could return null, to be more in line with what the XMLParser does... } if (is_int($out)) { $result = new \DateTime(); diff --git a/src/PhpXmlRpc.php b/src/PhpXmlRpc.php index c6c01b3b..4c3a80f0 100644 --- a/src/PhpXmlRpc.php +++ b/src/PhpXmlRpc.php @@ -138,7 +138,8 @@ class PhpXmlRpc /** * @var bool * Set to TRUE to make the library use DateTime objects instead of strings for all values parsed from incoming XML. - * NB: if the received strings are not parseable as dates, NULL will be returned! + * NB: if the received strings are not parseable as dates, NULL will be returned. To prevent that, enable as + * well `xmlrpc_reject_invalid_values`, so that invalid dates will be rejected by the library */ public static $xmlrpc_return_datetimes = false; @@ -146,7 +147,7 @@ class PhpXmlRpc * @var bool * Set to TRUE to make the library reject incoming xml which uses invalid data from xml-rpc Value elements, such * as base64 strings which can not be decoded, dateTime strings which do not represent a valid date, invalid bools, - * floats and inteers + * floats and integers */ public static $xmlrpc_reject_invalid_values = false; -- 2.47.0