📄 xmlrpc.inc
字号:
$this->debug=1;
}
else
{
$this->debug=0;
}
}
/*
* @access public
*/
function setCredentials($u, $p)
{
$this->username=$u;
$this->password=$p;
}
/*
* @access public
*/
function setCertificate($cert, $certpass)
{
$this->cert = $cert;
$this->certpass = $certpass;
}
/*
* @param string $key The name of a file containing a private SSL key
* @param string $keypass The secret password needed to use the private SSL key
* @access public
* NB: does not work in older php/curl installs
* Thanks to Daniel Convissor
*/
function setKey($key, $keypass)
{
$this->key = $key;
$this->keypass = $keypass;
}
/*
* @access public
*/
function setSSLVerifyPeer($i)
{
$this->verifypeer = $i;
}
/*
* @access public
*/
function setSSLVerifyHost($i)
{
$this->verifyhost = $i;
}
/**
* set proxy info
*
* @param string $proxyhost
* @param string $proxyport Defaults to 8080 for HTTP and 443 for HTTPS
* @param string $proxyusername
* @param string $proxypassword
* @access public
*/
function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '')
{
$this->proxy = $proxyhost;
$this->proxyport = $proxyport;
$this->proxy_user = $proxyusername;
$this->proxy_pass = $proxypassword;
}
/**
* Enables/disables reception of compressed xmlrpc responses.
* Note that enabling reception of compressed responses merely adds some standard
* http headers to xmlrpc requests. It is up to the xmlrpc server to return
* compressed responses when receiving such requests.
* @param string $compmethod either 'gzip', 'deflate', 'any' or ''
* @access public
*/
function setAcceptedCompression($compmethod)
{
if ($compmethod == 'any')
$this->accepted_compression = array('gzip', 'deflate');
else
$this->accepted_compression = array($compmethod);
}
/**
* Enables/disables http compression of xmlrpc request.
* Take care when sending compressed requests: servers might not support them
* (and automatic fallback to uncompressed requests is not yet implemented)
* @param string $compmethod either 'gzip', 'deflate' or ''
* @access public
*/
function setRequestCompression($compmethod)
{
$this->request_compression = $compmethod;
}
/**
* Adds a cookie to list of cookies that will be sent to server.
* NB: setting any param but name and value will turn the cookie into a 'version 1' cookie:
* do not do it unless you know what you are doing
* @param string $name
* @param string $value
* @param string $path
* @param string $domain
* @param string $port
* @access public
*
* @todo check correctness of urlencoding cookie value (copied from php way of doing it...)
*/
function setCookie($name, $value='', $path='', $domain='', $port=null)
{
$this->cookies[$name]['value'] = urlencode($value);
if ($path || $domain || $port)
{
$this->cookies[$name]['path'] = $path;
$this->cookies[$name]['domain'] = $domain;
$this->cookies[$name]['port'] = $port;
$this->cookies[$name]['version'] = 1;
}
else
{
$this->cookies[$name]['version'] = 0;
}
}
function& send($msg, $timeout=0, $method='')
{
// if user deos not specify http protocol, use native method of this client
// (i.e. method set during call to constructor)
if($method == '')
{
$method = $this->method;
}
if(is_array($msg))
{
// $msg is an array of xmlrpcmsg's
$r = $this->multicall($msg, $timeout, $method);
return $r;
}
elseif(is_string($msg))
{
$n =& new xmlrpcmsg('');
$n->payload = $msg;
$msg = $n;
}
// where msg is an xmlrpcmsg
$msg->debug=$this->debug;
if($method == 'https')
{
$r =& $this->sendPayloadHTTPS(
$msg,
$this->server,
$this->port,
$timeout,
$this->username,
$this->password,
$this->cert,
$this->certpass,
$this->proxy,
$this->proxyport,
$this->proxy_user,
$this->proxy_pass,
$this->keepalive,
$this->key,
$this->keypass
);
}
elseif($method == 'http11')
{
$r =& $this->sendPayloadCURL(
$msg,
$this->server,
$this->port,
$timeout,
$this->username,
$this->password,
null,
null,
$this->proxy,
$this->proxyport,
$this->proxy_user,
$this->proxy_pass,
'http',
$this->keepalive
);
}
else
{
$r =& $this->sendPayloadHTTP10(
$msg,
$this->server,
$this->port,
$timeout,
$this->username,
$this->password,
$this->proxy,
$this->proxyport,
$this->proxy_user,
$this->proxy_pass
);
}
return $r;
}
/**
* @access private
*/
function &sendPayloadHTTP10($msg, $server, $port, $timeout=0,$username='', $password='',
$proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='')
{
if($port==0)
{
$port=80;
}
// Only create the payload if it was not created previously
if(empty($msg->payload))
{
$msg->createPayload();
}
// Deflate request body and set appropriate request headers
if(function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate'))
{
if($this->request_compression == 'gzip')
{
$a = @gzencode($msg->payload);
if($a)
{
$msg->payload = $a;
$encoding_hdr = "Content-Encoding: gzip\r\n";
}
}
else
{
$a = @gzdeflate($msg->payload);
if($a)
{
$msg->payload = $a;
$encoding_hdr = "Content-Encoding: deflate\r\n";
}
}
}
else
{
$encoding_hdr = '';
}
// thanks to Grant Rauscher <grant7@firstworld.net>
// for this
$credentials='';
if($username!='')
{
$credentials='Authorization: Basic ' . base64_encode($username . ':' . $password) . "\r\n";
}
$accepted_encoding = '';
if(is_array($this->accepted_compression) && count($this->accepted_compression))
{
$accepted_encoding = 'Accept-Encoding: ' . implode(', ', $this->accepted_compression) . "\r\n";
}
$proxy_credentials = '';
if($proxyhost)
{
if($proxyport == 0)
{
$proxyport = 8080;
}
$connectserver = $proxyhost;
$connectport = $proxyport;
$uri = 'http://'.$server.':'.$port.$this->path;
if($proxyusername != '')
{
$proxy_credentials = 'Proxy-Authorization: Basic ' . base64_encode($proxyusername.':'.$proxypassword) . "\r\n";
}
}
else
{
$connectserver = $server;
$connectport = $port;
$uri = $this->path;
}
// Cookie generation, as per rfc2965 (version 1 cookies) or
// netscape's rules (version 0 cookies)
$cookieheader='';
foreach ($this->cookies as $name => $cookie)
{
if ($cookie['version'])
{
$cookieheader .= 'Cookie: $Version="' . $cookie['version'] . '"; ';
$cookieheader .= $name . '="' . $cookie['value'] . '";';
if ($cookie['path'])
$cookieheader .= ' $Path="' . $cookie['path'] . '";';
if ($cookie['domain'])
$cookieheader .= ' $Domain="' . $cookie['domain'] . '";';
if ($cookie['port'])
$cookieheader .= ' $Port="' . $cookie['domain'] . '";';
$cookieheader = substr($cookieheader, 0, -1) . "\r\n";
}
else
{
$cookieheader .= 'Cookie: ' . $name . '=' . $cookie['value'] . "\r\n";
}
}
$op= "POST " . $uri. " HTTP/1.0\r\n" .
"User-Agent: " . $GLOBALS['xmlrpcName'] . " " . $GLOBALS['xmlrpcVersion'] . "\r\n" .
"Host: ". $server . "\r\n" .
$credentials .
$proxy_credentials .
$accepted_encoding .
$encoding_hdr .
"Accept-Charset: " . implode(',', $this->accepted_charset_encodings) . "\r\n" .
$cookieheader .
"Content-Type: " . $msg->content_type . "\r\nContent-Length: " .
strlen($msg->payload) . "\r\n\r\n" .
$msg->payload;
if($timeout>0)
{
$fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr, $timeout);
}
else
{
$fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr);
}
if($fp)
{
if($timeout>0 && function_exists('stream_set_timeout'))
{
stream_set_timeout($fp, $timeout);
}
}
else
{
$this->errstr='Connect error: '.$this->errstr;
$r=&new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $this->errstr . ' (' . $this->errno . ')');
return $r;
}
if(!fputs($fp, $op, strlen($op)))
{
$this->errstr='Write error';
$r=&new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $this->errstr);
return $r;
}
else
{
// reset errno and errstr on succesful socket connection
$this->errstr = '';
}
// G. Giunta 2005/10/24: close socket before parsing.
// should yeld slightly better execution times, and make easier recursive calls (e.g. to follow http redirects)
//$resp=&$msg->parseResponseFile($fp);
$ipd='';
while($data=fread($fp, 32768))
{
// shall we check for $data === FALSE?
// as per the manual, it signals an error
$ipd.=$data;
}
fclose($fp);
$r =& $msg->parseResponse($ipd, false, $this->return_type);
return $r;
}
/**
* @access private
*/
function &sendPayloadHTTPS($msg, $server, $port, $timeout=0,$username='', $password='', $cert='',$certpass='',
$proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $keepalive=false, $key='', $keypass='')
{
$r =& $this->sendPayloadCURL($msg, $server, $port, $timeout, $username, $password, $cert, $certpass,
$proxyhost, $proxyport, $proxyusername, $proxypassword, 'https', $keepalive, $key, $keypass);
return $r;
}
/**
* Contributed by Justin Miller <justin@voxel.net>
* Requires curl to be built into PHP
* NB: CURL versions before 7.11.10 cannot use proxy to talk to https servers!
* @access private
*/
function &sendPayloadCURL($msg, $server, $port, $timeout=0, $username='', $password='', $cert='', $certpass='',
$proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $method='https', $keepalive=false,
$key='', $keypass='')
{
if(!function_exists('curl_init'))
{
$this->errstr='CURL unavailable on this install';
$r=&new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['no_curl'], $GLOBALS['xmlrpcstr']['no_curl']);
return $r;
}
if($method == 'https')
{
if(($info = curl_version()) &&
((is_string($info) && strpos($info, 'OpenSSL') === null) || (is_array($info) && !isset($info['ssl_version']))))
{
$this->errstr='SSL unavailable on this install';
$r=&new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['no_ssl'], $GLOBALS['xmlrpcstr']['no_ssl']);
return $r;
}
}
if($port == 0)
{
if($method == 'http')
{
$port = 80;
}
else
{
$port = 443;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -