From f16dc7afc8c7a866138511465a4d3362b704c33c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 13 Apr 2018 17:58:11 -0700 Subject: upgrade incutio xmlrpc library to use hubzilla curl wrapper --- library/IXR_Library.php | 61 +++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 43 deletions(-) (limited to 'library') diff --git a/library/IXR_Library.php b/library/IXR_Library.php index c249c4845..cb27973bb 100644 --- a/library/IXR_Library.php +++ b/library/IXR_Library.php @@ -606,7 +606,7 @@ class IXR_Client if (!$path) { // Assume we have been given a URL instead $bits = parse_url($server); - $this->server = $bits['host']; + $this->server = $server; $this->port = isset($bits['port']) ? $bits['port'] : 80; $this->path = isset($bits['path']) ? $bits['path'] : '/'; @@ -634,64 +634,39 @@ class IXR_Client $request = "POST {$this->path} HTTP/1.0$r"; // Merged from WP #8145 - allow custom headers - $this->headers['Host'] = $this->server; $this->headers['Content-Type'] = 'text/xml'; $this->headers['User-Agent'] = $this->useragent; $this->headers['Content-Length']= $length; + + $headers = []; + foreach( $this->headers as $header => $value ) { - $request .= "{$header}: {$value}{$r}"; + $headers[] .= "{$header}: {$value}"; } - $request .= $r; - $request .= $xml; - // Now send the request - if ($this->debug) { - echo '
'.htmlspecialchars($request)."\n
\n\n"; - } + //logger('server: ' . $this->server); + //logger('xml: ' . $xml); + //logger('headers: ' . print_r($headers,true)); - if ($this->timeout) { - $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); - } else { - $fp = @fsockopen($this->server, $this->port, $errno, $errstr); - } - if (!$fp) { + + $retries = 0; + $result = z_post_url($this->server,$xml,$retries, [ 'headers' => $headers] ); + + // logger('result: ' . print_r($result,true)); + + if (! $result['success']) { $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); return false; } - fputs($fp, $request); - $contents = ''; - $debugContents = ''; - $gotFirstLine = false; - $gettingHeaders = true; - while (!feof($fp)) { - $line = fgets($fp, 4096); - if (!$gotFirstLine) { - // Check line for '200' - if (strstr($line, '200') === false) { - $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); - return false; - } - $gotFirstLine = true; - } - if (trim($line) == '') { - $gettingHeaders = false; - } - if (!$gettingHeaders) { - // merged from WP #12559 - remove trim - $contents .= $line; - } - if ($this->debug) { - $debugContents .= $line; - } - } + if ($this->debug) { - echo '
'.htmlspecialchars($debugContents)."\n
\n\n"; + echo '
'.htmlspecialchars($result['header'] . "\n\n" . $result['body'])."\n
\n\n"; } // Now parse what we've got back - $this->message = new IXR_Message($contents); + $this->message = new IXR_Message($result['body']); if (!$this->message->parse()) { // XML error $this->error = new IXR_Error(-32700, 'parse error. not well formed'); -- cgit v1.2.3