protected function xmlCall($method, $params) { $output_options = array("output_type" => "xml", "verbosity" => "pretty", "escaping" => array("markup", "non-ascii", "non-print"), "version" => "xmlrpc", "encoding" => "UTF-8"); if ($params == null) { $request = xmlrpc_encode_request($method, null, $output_options); } else { $request = xmlrpc_encode_request($method, $params, $output_options); $request = $this->decodeEntities($request, ENT_QUOTES, "UTF-8"); } $host = $this->_params['host'] . ":" . $this->_params['port']; $url = "/"; $httpQuery = "POST " . $url . " HTTP/1.0\r\n"; $httpQuery .= "User-Agent: xmlrpc\r\n"; $httpQuery .= "Host: " . $host . "\r\n"; $httpQuery .= "Content-Type: text/xml\r\n"; $httpQuery .= "Content-Length: " . strlen($request) . "\r\n"; $httpQuery .= "Authorization: Basic " . base64_encode($this->_params['login']) . ":" . base64_encode($this->_params['password']) . "\r\n\r\n"; $httpQuery .= $request; $sock = null; if ($this->_params['scheme'] == "https") { $prot = "ssl://"; } $sock = @fsockopen($prot . $this->_params['host'], $this->_params['port'], $errNo, $errString); if (!$sock) { jLog::log('Erreur de connexion XMLRPC'); jLog::dump($prot . $this->_params['host']); jLog::dump($this->_params['port']); jLOG::dump($httpQuery); jLOG::dump(strlen($httpQuery)); jLOG::dump($errNo); jLOG::dump($errString); throw new jException('jelix~auth.error.lds.unreachable.server'); } if (!fwrite($sock, $httpQuery, strlen($httpQuery))) { throw new jException('jelix~auth.error.lds.request.not.send'); } fflush($sock); while (!feof($sock)) { $xmlResponse .= fgets($sock); } fclose($sock); $xmlResponse = substr($xmlResponse, strpos($xmlResponse, "\r\n\r\n") + 4); $booleanFalse = "<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><boolean>0</boolean></value>\n</param>\n</params>\n</methodResponse>\n"; if ($xmlResponse == $booleanFalse) { $xmlResponse = "0"; } else { $xmlResponseTmp = xmlrpc_decode($xmlResponse, "UTF-8"); if (!$xmlResponseTmp) { $xmlResponse = iconv("ISO-8859-1", "UTF-8", $xmlResponse); $xmlResponse = xmlrpc_decode($xmlResponse, "UTF-8"); } else { $xmlResponse = $xmlResponseTmp; } } return $xmlResponse; }
/** * call an xmlrpc call for a method * via the xmlrpc server in python (lmc-agent) * @param string $method name of the method * @param array $params array with param */ protected function xmlCall($method, $params) { $output_options = array("output_type" => "xml", "verbosity" => "pretty", "escaping" => array("markup", "non-ascii", "non-print"), "version" => "xmlrpc", "encoding" => "UTF-8"); //$output_options = array( "output_type" => "xml", "verbosity" => "pretty", "escaping" => array("markup", "non-ascii", "non-print"), "version" => "xmlrpc", "encoding" => "iso-8859-1" ); if ($params == null) { $request = xmlrpc_encode_request($method, null, $output_options); } else { $request = xmlrpc_encode_request($method, $params, $output_options); $request = $this->decodeEntities($request, ENT_QUOTES, "UTF-8"); } $host = $this->_params['host'] . ":" . $this->_params['port']; $url = "/"; $httpQuery = "POST " . $url . " HTTP/1.0\r\n"; $httpQuery .= "User-Agent: xmlrpc\r\n"; $httpQuery .= "Host: " . $host . "\r\n"; $httpQuery .= "Content-Type: text/xml\r\n"; $httpQuery .= "Content-Length: " . strlen($request) . "\r\n"; $httpQuery .= "Authorization: Basic " . base64_encode($this->_params['login']) . ":" . base64_encode($this->_params['password']) . "\r\n\r\n"; $httpQuery .= $request; $sock = null; // if crypted connexion if ($this->_params['scheme'] == "https") { $prot = "ssl://"; } $sock = @fsockopen($prot . $this->_params['host'], $this->_params['port'], $errNo, $errString); if (!$sock) { jLog::log('Erreur de connexion XMLRPC'); jLog::dump($prot . $this->_params['host']); jLog::dump($this->_params['port']); jLOG::dump($httpQuery); jLOG::dump(strlen($httpQuery)); jLOG::dump($errNo); jLOG::dump($errString); throw new jException('jelix~auth.error.lds.unreachable.server'); } if (!fwrite($sock, $httpQuery, strlen($httpQuery))) { throw new jException('jelix~auth.error.lds.request.not.send'); } fflush($sock); // We get the response from the server while (!feof($sock)) { $xmlResponse .= fgets($sock); } // Closing the connection fclose($sock); $xmlResponse = substr($xmlResponse, strpos($xmlResponse, "\r\n\r\n") + 4); /* To decode the XML into PHP, we use the (finaly a short function) xmlrpc_decode function. And that should've done the trick. We now have what ever the server function made in our $xmlResponse variable. Test if the XMLRPC result is a boolean value set to False. If it is the case, xmlrpc_decode will return an empty string. So we need to test this special case. */ $booleanFalse = "<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><boolean>0</boolean></value>\n</param>\n</params>\n</methodResponse>\n"; if ($xmlResponse == $booleanFalse) { $xmlResponse = "0"; } else { $xmlResponseTmp = xmlrpc_decode($xmlResponse, "UTF-8"); //if we cannot decode in UTF-8 if (!$xmlResponseTmp) { //conversion in UTF-8 $xmlResponse = iconv("ISO-8859-1", "UTF-8", $xmlResponse); $xmlResponse = xmlrpc_decode($xmlResponse, "UTF-8"); } else { $xmlResponse = $xmlResponseTmp; } } return $xmlResponse; }