/** * Load a response from an XML response * * Attempts to load a response from an XMLRPC response, autodetecting if it * is a fault response. * * @param string $response * @return boolean True if a valid XMLRPC response, false if a fault * response or invalid input */ public function loadXml($response) { if (!is_string($response)) { $this->_fault = new Zend_XmlRpc_Fault(650); $this->_fault->setEncoding($this->getEncoding()); return false; } // @see ZF-12293 - disable external entities for security purposes $loadEntities = libxml_disable_entity_loader(true); $useInternalXmlErrors = libxml_use_internal_errors(true); try { $dom = new DOMDocument(); $dom->loadXML($response); foreach ($dom->childNodes as $child) { if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) { #require_once 'Zend/XmlRpc/Exception.php'; throw new Zend_XmlRpc_Exception('Invalid XML: Detected use of illegal DOCTYPE'); } } // TODO: Locate why this passes tests but a simplexml import doesn't // $xml = simplexml_import_dom($dom); $xml = new SimpleXMLElement($response); libxml_disable_entity_loader($loadEntities); libxml_use_internal_errors($useInternalXmlErrors); } catch (Exception $e) { libxml_disable_entity_loader($loadEntities); libxml_use_internal_errors($useInternalXmlErrors); // Not valid XML $this->_fault = new Zend_XmlRpc_Fault(651); $this->_fault->setEncoding($this->getEncoding()); return false; } if (!empty($xml->fault)) { // fault response $this->_fault = new Zend_XmlRpc_Fault(); $this->_fault->setEncoding($this->getEncoding()); $this->_fault->loadXml($response); return false; } if (empty($xml->params)) { // Invalid response $this->_fault = new Zend_XmlRpc_Fault(652); $this->_fault->setEncoding($this->getEncoding()); return false; } try { if (!isset($xml->params) || !isset($xml->params->param) || !isset($xml->params->param->value)) { #require_once 'Zend/XmlRpc/Value/Exception.php'; throw new Zend_XmlRpc_Value_Exception('Missing XML-RPC value in XML'); } $valueXml = $xml->params->param->value->asXML(); $value = Zend_XmlRpc_Value::getXmlRpcValue($valueXml, Zend_XmlRpc_Value::XML_STRING); } catch (Zend_XmlRpc_Value_Exception $e) { $this->_fault = new Zend_XmlRpc_Fault(653); $this->_fault->setEncoding($this->getEncoding()); return false; } $this->setReturnValue($value->getValue()); return true; }
/** * Test encoding settings */ public function testSetGetEncoding() { $this->assertEquals('UTF-8', $this->_fault->getEncoding()); $this->assertEquals('UTF-8', Zend_XmlRpc_Value::getGenerator()->getEncoding()); $this->_fault->setEncoding('ISO-8859-1'); $this->assertEquals('ISO-8859-1', $this->_fault->getEncoding()); $this->assertEquals('ISO-8859-1', Zend_XmlRpc_Value::getGenerator()->getEncoding()); }
/** * Load XML and parse into request components * * @param string $request * @return boolean True on success, false if an error occurred. */ public function loadXml($request) { if (!is_string($request)) { $this->_fault = new Zend_XmlRpc_Fault(635); $this->_fault->setEncoding($this->getEncoding()); return false; } try { $xml = new SimpleXMLElement($request); } catch (Exception $e) { // Not valid XML $this->_fault = new Zend_XmlRpc_Fault(631); $this->_fault->setEncoding($this->getEncoding()); return false; } // Check for method name if (empty($xml->methodName)) { // Missing method name $this->_fault = new Zend_XmlRpc_Fault(632); $this->_fault->setEncoding($this->getEncoding()); return false; } $this->_method = (string) $xml->methodName; // Check for parameters if (!empty($xml->params)) { $types = array(); $argv = array(); foreach ($xml->params->children() as $param) { if (!isset($param->value)) { $this->_fault = new Zend_XmlRpc_Fault(633); $this->_fault->setEncoding($this->getEncoding()); return false; } try { $param = Zend_XmlRpc_Value::getXmlRpcValue($param->value, Zend_XmlRpc_Value::XML_STRING); $types[] = $param->getType(); $argv[] = $param->getValue(); } catch (Exception $e) { $this->_fault = new Zend_XmlRpc_Fault(636); $this->_fault->setEncoding($this->getEncoding()); return false; } } $this->_types = $types; $this->_params = $argv; } $this->_xml = $request; return true; }
/** * Load a response from an XML response * * Attempts to load a response from an XMLRPC response, autodetecting if it * is a fault response. * * @param string $response * @return boolean True if a valid XMLRPC response, false if a fault * response or invalid input */ public function loadXml($response) { if (!is_string($response)) { $this->_fault = new Zend_XmlRpc_Fault(650); $this->_fault->setEncoding($this->getEncoding()); return false; } // @see ZF-12293 - disable external entities for security purposes $loadEntities = libxml_disable_entity_loader(true); $useInternalXmlErrors = libxml_use_internal_errors(true); try { $xml = new SimpleXMLElement($response); libxml_disable_entity_loader($loadEntities); libxml_use_internal_errors($useInternalXmlErrors); } catch (Exception $e) { libxml_disable_entity_loader($loadEntities); libxml_use_internal_errors($useInternalXmlErrors); // Not valid XML $this->_fault = new Zend_XmlRpc_Fault(651); $this->_fault->setEncoding($this->getEncoding()); return false; } if (!empty($xml->fault)) { // fault response $this->_fault = new Zend_XmlRpc_Fault(); $this->_fault->setEncoding($this->getEncoding()); $this->_fault->loadXml($response); return false; } if (empty($xml->params)) { // Invalid response $this->_fault = new Zend_XmlRpc_Fault(652); $this->_fault->setEncoding($this->getEncoding()); return false; } try { if (!isset($xml->params) || !isset($xml->params->param) || !isset($xml->params->param->value)) { //require_once 'Zend/XmlRpc/Value/Exception.php'; throw new Zend_XmlRpc_Value_Exception('Missing XML-RPC value in XML'); } $valueXml = $xml->params->param->value->asXML(); $value = Zend_XmlRpc_Value::getXmlRpcValue($valueXml, Zend_XmlRpc_Value::XML_STRING); } catch (Zend_XmlRpc_Value_Exception $e) { $this->_fault = new Zend_XmlRpc_Fault(653); $this->_fault->setEncoding($this->getEncoding()); return false; } $this->setReturnValue($value->getValue()); return true; }
/** * Load a response from an XML response * * Attempts to load a response from an XMLRPC response, autodetecting if it * is a fault response. * * @param string $response * @return boolean True if a valid XMLRPC response, false if a fault * response or invalid input */ public function loadXml($response) { if (!is_string($response)) { $this->_fault = new Zend_XmlRpc_Fault(650); $this->_fault->setEncoding($this->getEncoding()); return false; } try { $useInternalXmlErrors = libxml_use_internal_errors(true); $xml = new SimpleXMLElement($response); libxml_use_internal_errors($useInternalXmlErrors); } catch (Exception $e) { libxml_use_internal_errors($useInternalXmlErrors); // Not valid XML $this->_fault = new Zend_XmlRpc_Fault(651); $this->_fault->setEncoding($this->getEncoding()); return false; } if (!empty($xml->fault)) { // fault response $this->_fault = new Zend_XmlRpc_Fault(); $this->_fault->setEncoding($this->getEncoding()); $this->_fault->loadXml($response); return false; } if (empty($xml->params)) { // Invalid response $this->_fault = new Zend_XmlRpc_Fault(652); $this->_fault->setEncoding($this->getEncoding()); return false; } try { if (!isset($xml->params) || !isset($xml->params->param) || !isset($xml->params->param->value)) { throw new Zend_XmlRpc_Value_Exception('Missing XML-RPC value in XML'); } $valueXml = $xml->params->param->value->asXML(); $value = Zend_XmlRpc_Value::getXmlRpcValue($valueXml, Zend_XmlRpc_Value::XML_STRING); } catch (Zend_XmlRpc_Value_Exception $e) { $this->_fault = new Zend_XmlRpc_Fault(653); $this->_fault->setEncoding($this->getEncoding()); return false; } $this->setReturnValue($value->getValue()); return true; }
/** * Load a response from an XML response * * Attempts to load a response from an XMLRPC response, autodetecting if it * is a fault response. * * @param string $response * @return boolean True if a valid XMLRPC response, false if a fault * response or invalid input */ public function loadXml($response) { if (!is_string($response)) { $this->_fault = new Zend_XmlRpc_Fault(650); $this->_fault->setEncoding($this->getEncoding()); return false; } try { $xml = @new SimpleXMLElement($response); } catch (Exception $e) { // Not valid XML $this->_fault = new Zend_XmlRpc_Fault(651); $this->_fault->setEncoding($this->getEncoding()); return false; } if (!empty($xml->fault)) { // fault response $this->_fault = new Zend_XmlRpc_Fault(); $this->_fault->setEncoding($this->getEncoding()); $this->_fault->loadXml($response); return false; } if (empty($xml->params)) { // Invalid response $this->_fault = new Zend_XmlRpc_Fault(652); $this->_fault->setEncoding($this->getEncoding()); return false; } try { if (!isset($xml->params) || !isset($xml->params->param) || !isset($xml->params->param->value)) { throw new Zend_XmlRpc_Value_Exception('Missing XML-RPC value in XML'); } $valueXml = $xml->params->param->value->asXML(); $valueXml = preg_replace('/<\?xml version=.*?\?>/i', '', $valueXml); $value = Zend_XmlRpc_Value::getXmlRpcValue(trim($valueXml), Zend_XmlRpc_Value::XML_STRING); } catch (Zend_XmlRpc_Value_Exception $e) { $this->_fault = new Zend_XmlRpc_Fault(653); $this->_fault->setEncoding($this->getEncoding()); return false; } $this->setReturnValue($value->getValue()); return true; }
/** * Load a response from an XML response * * Attempts to load a response from an XMLRPC response, autodetecting if it * is a fault response. * * @param string $response * @return boolean True if a valid XMLRPC response, false if a fault * response or invalid input */ public function loadXml($response) { if (!is_string($response)) { $this->_fault = new Zend_XmlRpc_Fault(650); $this->_fault->setEncoding($this->getEncoding()); return false; } try { $xml = Zend_Xml_Security::scan($response); } catch (Zend_Xml_Exception $e) { // Not valid XML $this->_fault = new Zend_XmlRpc_Fault(651); $this->_fault->setEncoding($this->getEncoding()); return false; } if (!empty($xml->fault)) { // fault response $this->_fault = new Zend_XmlRpc_Fault(); $this->_fault->setEncoding($this->getEncoding()); $this->_fault->loadXml($response); return false; } if (empty($xml->params)) { // Invalid response $this->_fault = new Zend_XmlRpc_Fault(652); $this->_fault->setEncoding($this->getEncoding()); return false; } try { if (!isset($xml->params) || !isset($xml->params->param) || !isset($xml->params->param->value)) { require_once 'Zend/XmlRpc/Value/Exception.php'; throw new Zend_XmlRpc_Value_Exception('Missing XML-RPC value in XML'); } $valueXml = $xml->params->param->value->asXML(); $value = Zend_XmlRpc_Value::getXmlRpcValue($valueXml, Zend_XmlRpc_Value::XML_STRING); } catch (Zend_XmlRpc_Value_Exception $e) { $this->_fault = new Zend_XmlRpc_Fault(653); $this->_fault->setEncoding($this->getEncoding()); return false; } $this->setReturnValue($value->getValue()); return true; }
/** * Load XML and parse into request components * * @param string $request * @return boolean True on success, false if an error occurred. */ public function loadXml($request) { if (!is_string($request)) { $this->_fault = new Zend_XmlRpc_Fault(635); $this->_fault->setEncoding($this->getEncoding()); return false; } // @see ZF-12293 - disable external entities for security purposes $loadEntities = libxml_disable_entity_loader(true); try { $dom = new DOMDocument(); $dom->loadXML($request); foreach ($dom->childNodes as $child) { if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) { // require_once 'Zend/XmlRpc/Exception.php'; throw new Zend_XmlRpc_Exception('Invalid XML: Detected use of illegal DOCTYPE'); } } $xml = simplexml_import_dom($dom); libxml_disable_entity_loader($loadEntities); } catch (Exception $e) { // Not valid XML $this->_fault = new Zend_XmlRpc_Fault(631); $this->_fault->setEncoding($this->getEncoding()); libxml_disable_entity_loader($loadEntities); return false; } // Check for method name if (empty($xml->methodName)) { // Missing method name $this->_fault = new Zend_XmlRpc_Fault(632); $this->_fault->setEncoding($this->getEncoding()); return false; } $this->_method = (string) $xml->methodName; // Check for parameters if (!empty($xml->params)) { $types = array(); $argv = array(); foreach ($xml->params->children() as $param) { if (!isset($param->value)) { $this->_fault = new Zend_XmlRpc_Fault(633); $this->_fault->setEncoding($this->getEncoding()); return false; } try { $param = Zend_XmlRpc_Value::getXmlRpcValue($param->value, Zend_XmlRpc_Value::XML_STRING); $types[] = $param->getType(); $argv[] = $param->getValue(); } catch (Exception $e) { $this->_fault = new Zend_XmlRpc_Fault(636); $this->_fault->setEncoding($this->getEncoding()); return false; } } $this->_types = $types; $this->_params = $argv; } $this->_xml = $request; return true; }
/** * Test encoding settings */ public function testSetGetEncoding() { $this->assertEquals('UTF-8', $this->_fault->getEncoding()); $this->_fault->setEncoding('ISO-8859-1'); $this->assertEquals('ISO-8859-1', $this->_fault->getEncoding()); }