2
0
forked from Wavyzz/dolibarr

Compatibility of nusoap with PHP8

This commit is contained in:
Laurent Destailleur
2020-12-12 15:37:15 +01:00
parent 4013eaa239
commit 5f476e7e7e
18 changed files with 625 additions and 435 deletions

View File

@@ -56,8 +56,8 @@ class soap_transport_http extends nusoap_base {
* @param boolean $use_curl Whether to try to force cURL use
* @access public
*/
function soap_transport_http($url, $curl_options = NULL, $use_curl = false){
parent::nusoap_base();
function __construct($url, $curl_options = NULL, $use_curl = false){
parent::__construct();
$this->debug("ctor url=$url use_curl=$use_curl curl_options:");
$this->appendDebug($this->varDump($curl_options));
$this->setURL($url);
@@ -121,12 +121,12 @@ class soap_transport_http extends nusoap_base {
$this->debug("parsed URL $k = $v");
$this->$k = $v;
}
// add any GET params to path
if(isset($u['query']) && $u['query'] != ''){
$this->path .= '?' . $u['query'];
}
// set default port
if(!isset($u['port'])){
if($u['scheme'] == 'https'){
@@ -135,10 +135,10 @@ class soap_transport_http extends nusoap_base {
$this->port = 80;
}
}
$this->uri = $this->path;
$this->digest_uri = $this->uri;
// build headers
if (!isset($u['port'])) {
$this->setHeader('Host', $this->host);
@@ -218,7 +218,7 @@ class soap_transport_http extends nusoap_base {
} else {
$this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str);
}
// test pointer
if(!$this->fp) {
$msg = 'Couldn\'t open socket connection to server ' . $this->url;
@@ -231,7 +231,7 @@ class soap_transport_http extends nusoap_base {
$this->setError($msg);
return false;
}
// set response timeout
$this->debug('set response timeout to ' . $response_timeout);
socket_set_timeout( $this->fp, $response_timeout);
@@ -320,10 +320,10 @@ class soap_transport_http extends nusoap_base {
// recent versions of cURL turn on peer/host checking by default,
// while PHP binaries are not compiled with a default location for the
// CA cert bundle, so disable peer/host checking.
//$this->setCurlOption(CURLOPT_CAINFO, 'f:\php-4.3.2-win32\extensions\curl-ca-bundle.crt');
//$this->setCurlOption(CURLOPT_CAINFO, 'f:\php-4.3.2-win32\extensions\curl-ca-bundle.crt');
$this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0);
$this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 0);
// support client certificates (thanks Tobias Boes, Doug Anarino, Eryan Ariobowo)
if ($this->authtype == 'certificate') {
$this->debug('set cURL certificate options');
@@ -410,7 +410,7 @@ class soap_transport_http extends nusoap_base {
* @access public
*/
function send($data, $timeout=0, $response_timeout=30, $cookies=NULL) {
$this->debug('entered send() with data of length: '.strlen($data));
$this->tryagain = true;
@@ -422,18 +422,18 @@ class soap_transport_http extends nusoap_base {
if (!$this->connect($timeout, $response_timeout)){
return false;
}
// send request
if (!$this->sendRequest($data, $cookies)){
return false;
}
// get response
$respdata = $this->getResponse();
} else {
$this->setError("Too many tries to get an OK response ($this->response_status_line)");
}
}
}
$this->debug('end of send()');
return $respdata;
}
@@ -453,7 +453,7 @@ class soap_transport_http extends nusoap_base {
function sendHTTPS($data, $timeout=0, $response_timeout=30, $cookies) {
return $this->send($data, $timeout, $response_timeout, $cookies);
}
/**
* if authenticating, set user credentials here
*
@@ -475,21 +475,21 @@ class soap_transport_http extends nusoap_base {
} elseif ($authtype == 'digest') {
if (isset($digestRequest['nonce'])) {
$digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1;
// calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html)
// A1 = unq(username-value) ":" unq(realm-value) ":" passwd
$A1 = $username. ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password;
// H(A1) = MD5(A1)
$HA1 = md5($A1);
// A2 = Method ":" digest-uri-value
$A2 = $this->request_method . ':' . $this->digest_uri;
// H(A2)
$HA2 = md5($A2);
// KD(secret, data) = H(concat(secret, ":", data))
// if qop == auth:
// request-digest = <"> < KD ( H(A1), unq(nonce-value)
@@ -500,7 +500,7 @@ class soap_transport_http extends nusoap_base {
// ) <">
// if qop is missing,
// request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <">
$unhashedDigest = '';
$nonce = isset($digestRequest['nonce']) ? $digestRequest['nonce'] : '';
$cnonce = $nonce;
@@ -509,10 +509,10 @@ class soap_transport_http extends nusoap_base {
} else {
$unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2;
}
$hashedDigest = md5($unhashedDigest);
$opaque = '';
$opaque = '';
if (isset($digestRequest['opaque'])) {
$opaque = ', opaque="' . $digestRequest['opaque'] . '"';
}
@@ -531,7 +531,7 @@ class soap_transport_http extends nusoap_base {
$this->authtype = $authtype;
$this->digestRequest = $digestRequest;
}
/**
* set the soapaction value
*
@@ -541,7 +541,7 @@ class soap_transport_http extends nusoap_base {
function setSOAPAction($soapaction) {
$this->setHeader('SOAPAction', '"' . $soapaction . '"');
}
/**
* use http encoding
*
@@ -561,7 +561,7 @@ class soap_transport_http extends nusoap_base {
$this->encoding = $enc;
}
}
/**
* set proxy info here
*
@@ -590,7 +590,7 @@ class soap_transport_http extends nusoap_base {
unsetHeader('Proxy-Authorization');
}
}
/**
* Test if the given string starts with a header that is to be skipped.
@@ -631,7 +631,7 @@ class soap_transport_http extends nusoap_base {
// length := 0
$length = 0;
$new = '';
// read chunk-size, chunk-extension (if any) and CRLF
// get the position of the linebreak
$chunkend = strpos($buffer, $lb);
@@ -646,7 +646,7 @@ class soap_transport_http extends nusoap_base {
while ($chunk_size > 0) {
$this->debug("chunkstart: $chunkstart chunk_size: $chunk_size");
$chunkend = strpos( $buffer, $lb, $chunkstart + $chunk_size);
// Just in case we got a broken connection
if ($chunkend == FALSE) {
$chunk = substr($buffer,$chunkstart);
@@ -655,7 +655,7 @@ class soap_transport_http extends nusoap_base {
$length += strlen($chunk);
break;
}
// read chunk-data and CRLF
$chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart);
// append chunk-data to entity-body
@@ -664,7 +664,7 @@ class soap_transport_http extends nusoap_base {
$length += strlen($chunk);
// read chunk-size and CRLF
$chunkstart = $chunkend + strlen($lb);
$chunkend = strpos($buffer, $lb, $chunkstart) + strlen($lb);
if ($chunkend == FALSE) {
break; //Just in case we got a broken connection
@@ -675,7 +675,7 @@ class soap_transport_http extends nusoap_base {
}
return $new;
}
/**
* Writes the payload, including HTTP headers, to $this->outgoing_payload.
*
@@ -720,7 +720,7 @@ class soap_transport_http extends nusoap_base {
// header/body separator
$this->outgoing_payload .= "\r\n";
// add data
$this->outgoing_payload .= $data;
}
@@ -792,7 +792,7 @@ class soap_transport_http extends nusoap_base {
*/
function getResponse(){
$this->incoming_payload = '';
if ($this->io_method() == 'socket') {
// loop until headers have been retrieved
$data = '';
@@ -863,7 +863,7 @@ class soap_transport_http extends nusoap_base {
$this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
}
}
// loop until msg has been received
if (isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked') {
$content_length = 2147483647; // ignore any content-length header
@@ -929,22 +929,22 @@ class soap_transport_http extends nusoap_base {
$this->debug('read body of length ' . strlen($data));
$this->incoming_payload .= $data;
$this->debug('received a total of '.strlen($this->incoming_payload).' bytes of data from server');
// close filepointer
if(
(isset($this->incoming_headers['connection']) && strtolower($this->incoming_headers['connection']) == 'close') ||
(isset($this->incoming_headers['connection']) && strtolower($this->incoming_headers['connection']) == 'close') ||
(! $this->persistentConnection) || feof($this->fp)){
fclose($this->fp);
$this->fp = false;
$this->debug('closed socket');
}
// connection was closed unexpectedly
if($this->incoming_payload == ''){
$this->setError('no response from server');
return false;
}
// decode transfer-encoding
// if(isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked'){
// if(!$data = $this->decodeChunked($data, $lb)){
@@ -955,7 +955,7 @@ class soap_transport_http extends nusoap_base {
// set decoded payload
// $this->incoming_payload = $header_data.$lb.$lb.$data;
// }
} else if ($this->io_method() == 'curl') {
// send and receive
$this->debug('send and receive with cURL');
@@ -981,7 +981,7 @@ class soap_transport_http extends nusoap_base {
// close curl
$this->debug('No cURL error, closing cURL');
curl_close($this->ch);
// try removing skippable headers
$savedata = $data;
while ($this->isSkippableCurlHeader($data)) {
@@ -1004,7 +1004,7 @@ class soap_transport_http extends nusoap_base {
}
}
}
// separate content from HTTP headers
if ($pos = strpos($data,"\r\n\r\n")) {
$lb = "\r\n";
@@ -1064,7 +1064,7 @@ class soap_transport_http extends nusoap_base {
$this->debug('Server wants digest authentication');
// remove "Digest " from our elements
$digestString = str_replace('Digest ', '', $this->incoming_headers['www-authenticate']);
// parse elements into array
$digestElements = explode(',', $digestString);
foreach ($digestElements as $val) {
@@ -1083,7 +1083,7 @@ class soap_transport_http extends nusoap_base {
$this->setError('HTTP authentication failed');
return false;
}
if (
($http_status >= 300 && $http_status <= 307) ||
($http_status >= 400 && $http_status <= 417) ||
@@ -1151,13 +1151,13 @@ class soap_transport_http extends nusoap_base {
} else {
$this->debug('No Content-Encoding header');
}
if(strlen($data) == 0){
$this->debug('no data after headers!');
$this->setError('no data present after HTTP headers');
return false;
}
return $data;
}
@@ -1229,7 +1229,7 @@ class soap_transport_http extends nusoap_base {
} else {
$path = '/';
}
$cookie_param = ';secure;';
if (strpos($cookie_str, $cookie_param) !== FALSE) {
$secure = true;
@@ -1248,12 +1248,12 @@ class soap_transport_http extends nusoap_base {
'path' => $path,
'expires' => $expires,
'secure' => $secure
);
);
return $cookie;
}
return false;
}
/**
* sort out cookies for the current request
*