Move ssl client send into xmlrpc_client class

This commit is contained in:
Miles Lott 2001-08-15 14:01:44 +00:00
parent 24944500f2
commit 51a572a9f5
2 changed files with 86 additions and 56 deletions

View File

@ -128,17 +128,9 @@
function _send_xmlrpc_ssl($method_name, $args, $url, $debug=True)
{
if(!function_exists(curl_init))
{
$this->debug('No curl functions available - use of ssl is invalid',$debug);
return False;
}
/* curl Method borrowed from:
http://sourceforge.net/tracker/index.php?func=detail&aid=427359&group_id=23199&atid=377731
*/
list($uri,$hostpart) = $this->_split_url($url . $this->urlparts['xmlrpc']);
$this->debug("opening curl to $url", $debug);
$hostpart = ereg_replace('https://','',$hostpart);
$hostpart = ereg_replace('http://','',$hostpart);
if(gettype($args) != 'array')
{
$arr[] = CreateObject('phpgwapi.xmlrpcval',$args,'string');
@ -147,51 +139,29 @@
{
while(list($key,$val) = @each($args))
{
$arr[] = CreateObject('phpgwapi.xmlrpcval',$val,'string');
$arr[] = CreateObject('phpgwapi.xmlrpcval',$val, 'string');
}
}
$f = CreateObject('phpgwapi.xmlrpcmsg',$method_name,$arr);
$content_len = strlen($f->serialize());
$cliversion = $GLOBALS['phpgw_info']['server']['versions']['phpgwapi'];
$http_request = 'POST ' . $uri . ' HTTP/1.0' . "\r\n"
. 'User-Agent: phpGroupware/' . $cliversion . '(PHP) ' . "\r\n"
. 'X-PHPGW-Server: ' . $GLOBALS['HTTP_HOST'] . ' ' . "\r\n"
. 'X-PHPGW-Version: ' . $cliversion . "\r\n"
. 'Content-Type: text/xml' . "\r\n"
. 'Content-Length: ' . $content_len . "\r\n\r\n"
. $f->serialize();
$this->debug("sending http request:</h3><xmp>\n" . $http_request . "\n</xmp>", $debug);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$hostpart);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $http_request);
curl_setopt($ch, CURLOPT_HEADER, 0);
$response_buf = curl_exec($ch);
curl_close($ch);
$this->debug("got response:</h3>.<xmp>\n$response_buf\n</xmp>\n", $debug);
$retval = '';
if (strlen($response_buf))
$f = CreateObject('phpgwapi.xmlrpcmsg', $method_name, $arr,'struct');
$this->debug("<pre>" . htmlentities($f->serialize()) . "</pre>\n",$debug);
$c = CreateObject('phpgwapi.xmlrpc_client',$this->urlparts['xmlrpc'], $hostpart, 80);
$c->setDebug(1);
$r = $c->send($f,0,True);
if (!$r)
{
$xml_begin = substr($response_buf, strpos($response_buf, "<?xml"));
if (strlen($xml_begin))
{
$retval = xmlrpc_decode($xml_begin);
}
else
{
$this->debug('Error: no xml start found from'.$hostpart.'!');
}
$this->debug('send failed');
}
$v = $r->value();
if (!$r->faultCode())
{
$this->debug('<hr>I got this value back<br><pre>' . htmlentities($r->serialize()) . '</pre><hr>',$debug);
}
else
{
$this->debug('Error: no response from '.$hostpart.'!');
$this->debug('Fault Code: ' . $r->faultCode() . ' Reason "' . $r->faultString() . '"<br>',$debug);
}
$this->result = $retval;
$this->result = xmlrpc_decode($v);
return $this->result;
}

View File

@ -54,16 +54,29 @@
$this->password = $p;
}
function send($msg, $timeout=0)
function send($msg, $timeout=0, $ssl=False)
{
// where msg is an xmlrpcmsg
$msg->debug=$this->debug;
return $this->sendPayloadHTTP10(
$msg,
$this->server, $this->port,
$timeout, $this->username,
$this->password
);
$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="")
@ -112,5 +125,52 @@
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;
}
}
?>