egroupware_official/phpgwapi/inc/class.xmlrpc_client.inc.php

177 lines
4.6 KiB
PHP
Raw Normal View History

<?php
// by Edd Dumbill (C) 1999-2001
// <edd@usefulinc.com>
// xmlrpc.inc,v 1.18 2001/07/06 18:23:57 edmundd
// License is granted to use or modify this software ("XML-RPC for PHP")
// for commercial or non-commercial use provided the copyright of the author
// is preserved in any distributed or derivative work.
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class xmlrpc_client
{
var $path;
var $server;
var $port;
var $errno;
var $errstring;
var $debug=0;
2001-08-13 23:56:41 +02:00
var $username = '';
var $password = '';
function xmlrpc_client($path='', $server='', $port=80)
{
$this->port = $port;
$this->server = $server;
$this->path = $path;
}
function setDebug($in)
{
if ($in)
{
2001-08-13 23:56:41 +02:00
$this->debug = 1;
}
else
{
2001-08-13 23:56:41 +02:00
$this->debug = 0;
}
}
function setCredentials($u, $p)
{
2001-08-13 23:56:41 +02:00
$this->username = $u;
$this->password = $p;
}
function send($msg, $timeout=0, $ssl=False)
{
// where msg is an xmlrpcmsg
$msg->debug = $this->debug;
if($ssl)
{
return $this->ssl_sendPayloadHTTP10(
$msg,
$this->server, $this->port,
$timeout, $this->username,
$this->password
);
}
else
{
return $this->sendPayloadHTTP10(
$msg,
$this->server, $this->port,
$timeout, $this->username,
$this->password
);
}
}
function sendPayloadHTTP10($msg, $server, $port, $timeout=0,$username="", $password="")
{
if($timeout>0)
{
$fp=fsockopen($server, $port,&$this->errno, &$this->errstr, $timeout);
}
else
{
$fp=fsockopen($server, $port,&$this->errno, &$this->errstr);
}
if (!$fp)
{
return 0;
}
// Only create the payload if it was not created previously
if(empty($msg->payload))
{
$msg->createPayload();
}
// thanks to Grant Rauscher <grant7@firstworld.net>
// for this
2001-08-13 23:56:41 +02:00
$credentials = '';
if ($username!="")
{
2001-08-13 23:56:41 +02:00
$credentials = "Authorization: Basic " . base64_encode($username . ":" . $password) . "\r\n";
}
2001-08-13 23:56:41 +02:00
$op = "POST " . $this->path . " HTTP/1.0\r\nUser-Agent: PHP XMLRPC 1.0\r\n"
. "Host: ". $this->server . "\r\n"
2001-08-13 23:56:41 +02:00
. 'X-PHPGW-Server: ' . $this->server . ' ' . "\r\n"
. 'X-PHPGW-Version: ' . $GLOBALS['phpgw_info']['server']['versions']['phpgwapi'] . "\r\n"
. $credentials
. "Content-Type: text/xml\r\nContent-Length: "
. strlen($msg->payload) . "\r\n\r\n"
. $msg->payload;
if (!fputs($fp, $op, strlen($op)))
{
$this->errstr="Write error";
return 0;
}
2001-08-13 23:56:41 +02:00
$resp = $msg->parseResponseFile($fp);
fclose($fp);
return $resp;
}
function ssl_sendPayloadHTTP10($msg, $server, $port, $timeout=0,$username='', $password='')
{
if(!function_exists(curl_init))
{
$this->errstr = 'No curl functions available - use of ssl is invalid';
return False;
}
/* curl Method borrowed from:
http://sourceforge.net/tracker/index.php?func=detail&aid=427359&group_id=23199&atid=377731
*/
// Only create the payload if it was not created previously
if(empty($msg->payload))
{
$msg->createPayload();
}
// thanks to Grant Rauscher <grant7@firstworld.net>
// for this
$credentials = '';
if ($username!='')
{
$credentials = "Authorization: Basic " . base64_encode($username . ':' . $password) . "\r\n";
}
$op = "POST " . $this->path . " HTTP/1.0\r\nUser-Agent: PHP XMLRPC 1.0\r\n"
. "Host: ". $this->server . "\r\n"
. 'X-PHPGW-Server: ' . $this->server . ' ' . "\r\n"
. 'X-PHPGW-Version: ' . $GLOBALS['phpgw_info']['server']['versions']['phpgwapi'] . "\r\n"
. $credentials
. "Content-Type: text/xml\r\nContent-Length: "
. strlen($msg->payload) . "\r\n\r\n"
. $msg->payload;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$this->server);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $op);
curl_setopt($ch, CURLOPT_HEADER, 0);
$response_buf = curl_exec($ch);
curl_close($ch);
$resp = $msg->parseResponse($response_buf);
return $resp;
}
}
?>