From 2c4a8a7d6cab3083caaf26d691d02549220624d0 Mon Sep 17 00:00:00 2001 From: gggeek Date: Tue, 24 Jan 2023 23:34:30 +0000 Subject: [PATCH] add support for interop error codes --- NEWS.md | 3 +++ src/PhpXmlRpc.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/Server.php | 16 ++++++++-------- 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/NEWS.md b/NEWS.md index 910431a7..03a49fc1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -56,6 +56,9 @@ * fixed: receiving integers which use the '' xml tag +* new: method `PhpXmlRpc::useInteropFaults()` can be used to make the library change the error codes it generates to + match the spec described at https://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php + * new: added the `Client::setTimeout` method, meant to replace usage of the `$timeout` argument in calls to `send` and `multicall` diff --git a/src/PhpXmlRpc.php b/src/PhpXmlRpc.php index b2c96dde..81166bcb 100644 --- a/src/PhpXmlRpc.php +++ b/src/PhpXmlRpc.php @@ -203,6 +203,37 @@ class PhpXmlRpc */ public static $xmlrpc_methodname_format = '|^[ \t]*[a-zA-Z0-9_.:/]+[ \t]*$|'; + /// @todo review - should we use the range -32099 .. -32000 for some server erors? + public static $xmlrpcerr_interop = array( + 'unknown_method' => -32601, + 'invalid_return' => 2, + 'incorrect_params' => -32602, + 'introspect_unknown' => -32601, // this shares the same code but has a separate meaning from 'unknown_method'... + 'http_error' => 32300, + 'no_data' => -32700, + 'no_ssl' => -32400, + 'curl_fail' => -32400, + 'invalid_request' => -32600, + 'no_curl' => -32400, + 'server_error' => -32500, + 'multicall_error' => -32700, + 'multicall_notstruct' => -32600, + 'multicall_nomethod' => -32601, + 'multicall_notstring' => -32600, + 'multicall_recursion' => -32603, + 'multicall_noparams' => -32602, + 'multicall_notarray' => -32600, + 'no_http2' => -32400, + 'invalid_xml' => -32700, + 'xml_not_compliant' => -32700, + 'xml_parsing_error' => -32700, + 'cannot_decompress' => -32400, + 'decompress_fail' => -32300, + 'dechunk_fail' => -32300, + 'server_cannot_decompress' => -32300, + 'server_decompress_fail' => -32300, + ); + /** * A function to be used for compatibility with legacy code: it creates all global variables which used to be declared, * such as library version etc... @@ -279,4 +310,18 @@ class PhpXmlRpc Wrapper::setLogger($logger); XMLParser::setLogger($logger); } + + /** + * Makes the library use the error codes detailed at https://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php + * + * @return void + * + * @tofo feature creep - allow switching back to the original set of codes; querying the current mode + */ + public static function useInteropFaults() + { + self::$xmlrpcerr = self::$xmlrpcerr_interop; + + self::$xmlrpcerruser = -32000; + } } diff --git a/src/Server.php b/src/Server.php index 632c395b..a5bcb081 100644 --- a/src/Server.php +++ b/src/Server.php @@ -578,7 +578,7 @@ class Server PhpXmlRpc::$xmlrpcerrxml + (int)$matches[1], $xmlRpcParser->_xh['isf_reason']); } elseif ($xmlRpcParser->_xh['isf']) { - /// @todo separate better the various cases, as we have done in Request::parseResponse: invalid xml-rpc, + /// @todo separate better the various cases, as we have done in Request::parseResponse: invalid xml-rpc vs. /// parsing error return new Response( 0, @@ -988,13 +988,13 @@ class Server ); } - /// @todo add support for "standard" error codes - //if (...) { - // $outAr['faults_interop'] = array( - // 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', - // 'specVersion' => 20010516 - // ); - //} + // support for "standard" error codes + if (PhpXmlRpc::$xmlrpcerr['unknown_method'] == -32601) { + $outAr['faults_interop'] = array( + 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', + 'specVersion' => 20010516 + ); + } return $outAr; } -- 2.47.0