From: mjollnir_ Date: Tue, 2 Sep 2008 14:11:53 +0000 (+0000) Subject: MDL-16289 - actually unpack xmlrpc errors rather than just whinge the payload is... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a5248bee7bf8867e434f6c09477dc4e113e71fd1;p=moodle.git MDL-16289 - actually unpack xmlrpc errors rather than just whinge the payload is unencrypted --- diff --git a/mnet/xmlrpc/client.php b/mnet/xmlrpc/client.php index f2a983efb7..d6d5936814 100644 --- a/mnet/xmlrpc/client.php +++ b/mnet/xmlrpc/client.php @@ -249,8 +249,9 @@ class mnet_xmlrpc_client { } } else { - - if (! empty($crypt_parser->error)) { + if (! empty($crypt_parser->remoteerror)) { + $this->error[] = '4: remote server error: ' . $crypt_parser->remoteerror; + } else if (! empty($crypt_parser->error)) { $crypt_parser_error = $crypt_parser->error[0]; $message = '3:XML Parse error in payload: '.$crypt_parser_error['string']."\n"; diff --git a/mnet/xmlrpc/xmlparser.php b/mnet/xmlrpc/xmlparser.php index 1d74381d25..e62743d4a9 100644 --- a/mnet/xmlrpc/xmlparser.php +++ b/mnet/xmlrpc/xmlparser.php @@ -43,6 +43,8 @@ class mnet_encxml_parser { $this->payload_encrypted = false; $this->cipher = array(); $this->error = array(); + $this->remoteerror = null; + $this->errorstarted = false; return true; } @@ -113,6 +115,10 @@ class mnet_encxml_parser { } } + if (!empty($this->remoteerror)) { + return false; + } + if (count($this->cipher) > 0) { $this->cipher = array_values($this->cipher); $this->payload_encrypted = true; @@ -166,6 +172,8 @@ class mnet_encxml_parser { $this->cipher[$this->tag_number] = ''; $handler = 'parse_cipher'; break; + case 'FAULT': + $handler = 'parse_fault'; default: break; } @@ -264,7 +272,27 @@ class mnet_encxml_parser { * @return bool True */ function discard_data($parser, $data) { - // Not interested + if (!$this->errorstarted) { + // Not interested + return true; + } + $data = trim($data); + if (isset($this->errorstarted->faultstringstarted) && !empty($data)) { + $this->remoteerror .= ', message: ' . $data; + } else if (isset($this->errorstarted->faultcodestarted)) { + $this->remoteerror = 'code: ' . $data; + unset($this->errorstarted->faultcodestarted); + } else if ($data == 'faultCode') { + $this->errorstarted->faultcodestarted = true; + } else if ($data == 'faultString') { + $this->errorstarted->faultstringstarted = true; + } + return true; + + } + + function parse_fault($parser, $data) { + $this->errorstarted = new StdClass; return true; }