Skip to content

Commit c8a221b

Browse files
committed
fix error code returned by server for invalid xml when in interop mode
1 parent 8b67178 commit c8a221b

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
* improved: prepare the debugger for json-rpc 2.0 support, which will be in a pending release of the PhpJsonRpc library
1111

12+
* improved: when using "Interop" error codes, use error code -32700 when xml parsing fails server-side, instead of 100+X
13+
1214
* improved: changes some error numbers to avoid conflicts - now errors related to http compression use the range 153-157,
1315
while the range 103-107 is reserved for xml parsing errors
1416

src/PhpXmlRpc.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class PhpXmlRpc
3939
'unsupported_option' => 20, // client
4040
// the following 3 are meant to give greater insight than 'invalid_return'. They use the same code for BC,
4141
// but you can override their value in your own code
42-
'invalid_xml' => 2, // client
42+
'invalid_xml' => 2, // client (and server, when interop mode is enabled)
4343
'xml_not_compliant' => 2, // client
4444
'xml_parsing_error' => 2, // client
4545

@@ -129,7 +129,8 @@ class PhpXmlRpc
129129
* @var int
130130
* Let XML parse errors start at 100.
131131
* The final code will be 100 + X, with X coming from https://www.php.net/manual/en/xml.error-codes.php.
132-
* Values are known to go from 1 (XML_ERROR_NO_MEMORY) to 21 (XML_ERROR_EXTERNAL_ENTITY_HANDLING)
132+
* Values are known to go from 1 (XML_ERROR_NO_MEMORY) to 21 (XML_ERROR_EXTERNAL_ENTITY_HANDLING).
133+
* Used only server-side
133134
*/
134135
public static $xmlrpcerrxml = 100;
135136

@@ -251,6 +252,11 @@ public static function useInteropFaults()
251252
self::$xmlrpcerruser = -Interop::$xmlrpcerruser;
252253
}
253254

255+
public static function isUsingInteropFaults()
256+
{
257+
return self::$xmlrpcerruser == -Interop::$xmlrpcerruser;
258+
}
259+
254260
/**
255261
* A function to be used for compatibility with legacy code: it creates all global variables which used to be declared,
256262
* such as library version etc...

src/Request.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ public function parseResponse($data = '', $headersProcessed = false, $returnType
334334

335335
// BC break: in the past for some cases we used the error message: 'XML error at line 1, check URL'
336336

337-
// Q: should we give back an error with variable error number, as we do server-side? But if we do, will
338-
// we be able to tell apart the two cases? In theory, we never emit invalid xml on our end, but
339-
// there could be proxies meddling with the request, or network data corruption...
337+
// @todo should we give back an error with variable error number, as we do server-side? But if we do, will
338+
// we be able to tell apart the two cases? In theory, we never emit invalid xml on our end, but
339+
// there could be proxies meddling with the request, or network data corruption...
340340

341341
$r = new Response(0, PhpXmlRpc::$xmlrpcerr['invalid_xml'],
342342
PhpXmlRpc::$xmlrpcstr['invalid_xml'] . ' ' . $_xh['isf_reason'], '', $httpResponse);

src/Server.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,10 +680,11 @@ public function parseRequest($data, $reqEncoding = '')
680680

681681
if ($_xh['isf'] == 3) {
682682
// (BC) we return XML error as a faultCode
683+
// unless we are in "interop faults" mode
683684
preg_match('/^XML error ([0-9]+)/', $_xh['isf_reason'], $matches);
684685
return new static::$responseClass(
685686
0,
686-
PhpXmlRpc::$xmlrpcerrxml + (int)$matches[1],
687+
(PhpXmlRpc::isUsingInteropFaults() ? PhpXmlRpc::$xmlrpcerr['invalid_xml'] : PhpXmlRpc::$xmlrpcerrxml + (int)$matches[1]),
687688
$_xh['isf_reason']);
688689
} elseif ($_xh['isf']) {
689690
/// @todo separate better the various cases, as we have done in Request::parseResponse: invalid xml-rpc vs.

0 commit comments

Comments
 (0)