📄 rpc.php
字号:
} $this->headers .= $this->path. " HTTP/1.0\r\n"; $this->headers .= "User-Agent: PEAR XML_RPC\r\n"; $this->headers .= 'Host: ' . $this->server . "\r\n"; if ($this->proxy && $this->proxy_user) { $this->headers .= 'Proxy-Authorization: Basic ' . base64_encode("$this->proxy_user:$this->proxy_pass") . "\r\n"; } // thanks to Grant Rauscher <grant7@firstworld.net> for this if ($this->username) { $this->headers .= 'Authorization: Basic ' . base64_encode("$this->username:$this->password") . "\r\n"; } $this->headers .= "Content-Type: text/xml\r\n"; $this->headers .= 'Content-Length: ' . strlen($msg->payload); return true; }}/** * The methods and properties for interpreting responses to XML RPC requests * * @category Web Services * @package XML_RPC * @author Edd Dumbill <edd@usefulinc.com> * @author Stig Bakken <stig@php.net> * @author Martin Jansen <mj@php.net> * @author Daniel Convissor <danielc@php.net> * @copyright 1999-2001 Edd Dumbill, 2001-2005 The PHP Group * @version Release: 1.4.4 * @link http://pear.php.net/package/XML_RPC */class XML_RPC_Response extends XML_RPC_Base{ var $xv; var $fn; var $fs; var $hdrs; /** * @return void */ function XML_RPC_Response($val, $fcode = 0, $fstr = '') { if ($fcode != 0) { $this->fn = $fcode; $this->fs = htmlspecialchars($fstr); } else { $this->xv = $val; } } /** * @return int the error code */ function faultCode() { if (isset($this->fn)) { return $this->fn; } else { return 0; } } /** * @return string the error string */ function faultString() { return $this->fs; } /** * @return mixed the value */ function value() { return $this->xv; } /** * @return string the error message in XML format */ function serialize() { $rs = "<methodResponse>\n"; if ($this->fn) { $rs .= "<fault> <value> <struct> <member> <name>faultCode</name> <value><int>" . $this->fn . "</int></value> </member> <member> <name>faultString</name> <value><string>" . $this->fs . "</string></value> </member> </struct> </value></fault>"; } else { $rs .= "<params>\n<param>\n" . $this->xv->serialize() . "</param>\n</params>"; } $rs .= "\n</methodResponse>"; return $rs; }}/** * The methods and properties for composing XML RPC messages * * @category Web Services * @package XML_RPC * @author Edd Dumbill <edd@usefulinc.com> * @author Stig Bakken <stig@php.net> * @author Martin Jansen <mj@php.net> * @author Daniel Convissor <danielc@php.net> * @copyright 1999-2001 Edd Dumbill, 2001-2005 The PHP Group * @version Release: 1.4.4 * @link http://pear.php.net/package/XML_RPC */class XML_RPC_Message extends XML_RPC_Base{ /** * The current debug mode (1 = on, 0 = off) * @var integer */ var $debug = 0; /** * The encoding to be used for outgoing messages * * Defaults to the value of <var>$GLOBALS['XML_RPC_defencoding']</var> * * @var string * @see XML_RPC_Message::setSendEncoding(), * $GLOBALS['XML_RPC_defencoding'], XML_RPC_Message::xml_header() */ var $send_encoding = ''; /** * The method presently being evaluated * @var string */ var $methodname = ''; /** * @var array */ var $params = array(); /** * The XML message being generated * @var string */ var $payload = ''; /** * @return void */ function XML_RPC_Message($meth, $pars = 0) { $this->methodname = $meth; if (is_array($pars) && sizeof($pars) > 0) { for ($i = 0; $i < sizeof($pars); $i++) { $this->addParam($pars[$i]); } } } /** * Produces the XML declaration including the encoding attribute * * The encoding is determined by this class' <var>$send_encoding</var> * property. If the <var>$send_encoding</var> property is not set, use * <var>$GLOBALS['XML_RPC_defencoding']</var>. * * @return string the XML declaration and <methodCall> element * * @see XML_RPC_Message::setSendEncoding(), * XML_RPC_Message::$send_encoding, $GLOBALS['XML_RPC_defencoding'] */ function xml_header() { global $XML_RPC_defencoding; if (!$this->send_encoding) { $this->send_encoding = $XML_RPC_defencoding; } return '<?xml version="1.0" encoding="' . $this->send_encoding . '"?>' . "\n<methodCall>\n"; } /** * @return string the closing </methodCall> tag */ function xml_footer() { return "</methodCall>\n"; } /** * @return void * * @uses XML_RPC_Message::xml_header(), XML_RPC_Message::xml_footer() */ function createPayload() { $this->payload = $this->xml_header(); $this->payload .= '<methodName>' . $this->methodname . "</methodName>\n"; $this->payload .= "<params>\n"; for ($i = 0; $i < sizeof($this->params); $i++) { $p = $this->params[$i]; $this->payload .= "<param>\n" . $p->serialize() . "</param>\n"; } $this->payload .= "</params>\n"; $this->payload .= $this->xml_footer(); $this->payload = ereg_replace("[\r\n]+", "\r\n", $this->payload); } /** * @return string the name of the method */ function method($meth = '') { if ($meth != '') { $this->methodname = $meth; } return $this->methodname; } /** * @return string the payload */ function serialize() { $this->createPayload(); return $this->payload; } /** * @return void */ function addParam($par) { $this->params[] = $par; } /** * Obtains an XML_RPC_Value object for the given parameter * * @param int $i the index number of the parameter to obtain * * @return object the XML_RPC_Value object. * If the parameter doesn't exist, an XML_RPC_Response object. * * @since Returns XML_RPC_Response object on error since Release 1.3.0 */ function getParam($i) { global $XML_RPC_err, $XML_RPC_str; if (isset($this->params[$i])) { return $this->params[$i]; } else { $this->raiseError('The submitted request did not contain this parameter', XML_RPC_ERROR_INCORRECT_PARAMS); return new XML_RPC_Response(0, $XML_RPC_err['incorrect_params'], $XML_RPC_str['incorrect_params']); } } /** * @return int the number of parameters */ function getNumParams() { return sizeof($this->params); } /** * Sets the XML declaration's encoding attribute * * @param string $type the encoding type (ISO-8859-1, UTF-8 or US-ASCII) * * @return void * * @see XML_RPC_Message::$send_encoding, XML_RPC_Message::xml_header() * @since Method available since Release 1.2.0 */ function setSendEncoding($type) { $this->send_encoding = $type; } /** * Determine the XML's encoding via the encoding attribute * in the XML declaration * * If the encoding parameter is not set or is not ISO-8859-1, UTF-8 * or US-ASCII, $XML_RPC_defencoding will be returned. * * @param string $data the XML that will be parsed * * @return string the encoding to be used * * @link http://php.net/xml_parser_create * @since Method available since Release 1.2.0 */ function getEncoding($data) { global $XML_RPC_defencoding; if (preg_match('/<\?xml[^>]*\s*encoding\s*=\s*[\'"]([^"\']*)[\'"]/i', $data, $match)) { $match[1] = trim(strtoupper($match[1])); switch ($match[1]) { case 'ISO-8859-1': case 'UTF-8': case 'US-ASCII': return $match[1]; break; default: return $XML_RPC_defencoding; } } else { return $XML_RPC_defencoding; } } /** * @return object a new XML_RPC_Response object */ function parseResponseFile($fp) { $ipd = ''; while ($data = @fread($fp, 8192)) { $ipd .= $data; } return $this->parseResponse($ipd); } /** * @return object a new XML_RPC_Response object */ function parseResponse($data = '') { global $XML_RPC_xh, $XML_RPC_err, $XML_RPC_str, $XML_RPC_defencoding; $encoding = $this->getEncoding($data); $parser_resource = xml_parser_create($encoding); $parser = (int) $parser_resource; $XML_RPC_xh = array(); $XML_RPC_xh[$parser] = array(); $XML_RPC_xh[$parser]['cm'] = 0; $XML_RPC_xh[$parser]['isf'] = 0; $XML_RPC_xh[$parser]['ac'] = ''; $XML_RPC_xh[$parser]['qt'] = ''; $XML_RPC_xh[$parser]['stack'] = array(); $XML_RPC_xh[$parser]['valuestack'] = array(); xml_parser_set_option($parser_resource, XML_OPTION_CASE_FOLDING, true); xml_set_element_handler($parser_resource, 'XML_RPC_se', 'XML_RPC_ee'); xml_set_character_data_handler($parser_resource, 'XML_RPC_cd'); $hdrfnd = 0; if ($this->debug) { print "\n<pre>---GOT---\n"; print isset($_SERVER['SERVER_PROTOCOL']) ? htmlspecialchars($data) : $data; print "\n---END---</pre>\n"; } // See if response is a 200 or a 100 then a 200, else raise error. // But only do this if we're using the HTTP protocol. if (ereg('^HTTP', $data) && !ereg('^HTTP/[0-9\.]+ 200 ', $data) && !preg_match('@^HTTP/[0-9\.]+ 10[0-9]([A-Za-z ]+)?[\r\n]+HTTP/[0-9\.]+ 200@', $data)) { $errstr = substr($data, 0, strpos($data, "\n") - 1); error_log('HTTP error, got response: ' . $errstr); $r = new XML_RPC_Response(0, $XML_RPC_err['http_error'], $XML_RPC_str['http_error'] . ' (' . $errstr . ')'); xml_parser_free($parser_resource); return $r; } // gotta get rid of headers here if (!$hdrfnd && ($brpos = strpos($data,"\r\n\r\n"))) { $XML_RPC_xh[$parser]['ha'] = substr($data, 0, $brpos); $data = substr($data, $brpos + 4); $hdrfnd = 1; } /* * be tolerant of junk after methodResponse * (e.g. javascript automatically inserted by free hosts) * thanks to Luca Mariano <luca.mariano@email.it> */ $data = substr($data, 0, strpos($data, "</methodResponse>") + 17); if (!xml_parse($parser_resource, $data, sizeof($data))) { // thanks to Peter Kocks <peter.kocks@baygate.com> if (xml_get_current_line_number($parser_resource) == 1) { $errstr = 'XML error at line 1, check URL'; } else { $errstr = sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($parser_resource)), xml_get_current_line_number($parser_resource)); } error_log($errstr); $r = new XML_RPC_Response(0, $XML_RPC_err['invalid_return'], $XML_RPC_str['invalid_return']); xml_parser_free($parser_resource); return $r; } xml_parser_free($parser_resource); if ($this->debug) { print "\n<pre>---PARSED---\n"; var_dump($XML_RPC_xh[$parser]['value']); print "---END---</pre>\n"; } if ($XML_RPC_xh[$parser]['isf'] > 1) { $r = new XML_RPC_Response(0, $XML_RPC_err['invalid_return'], $XML_RPC_str['invalid_return'].' '.$XML_RPC_xh[$parser]['isf_reason']); } elseif (!is_object($XML_RPC_xh[$parser]['value'])) { // then something odd has happened // and it's time to generate a client side error // indicating something odd went on $r = new XML_RPC_Response(0, $XML_RPC_err['invalid_return'], $XML_RPC_str['invalid_return']); } else { $v = $XML_RPC_xh[$parser]['value']; $allOK=1; if ($XML_RPC_xh[$parser]['isf']) { $f = $v->structmem('faultCode'); $fs = $v->structmem('faultString'); $r = new XML_RPC_Response($v, $f->scalarval(), $fs->scalarval()); } else { $r = new XML_RPC_Response($v); } } $r->hdrs = split("\r?\n", $XML_RPC_xh[$parser]['ha'][1]); return $r; }}/** * The methods and properties that represent data in XML RPC format * * @category Web Services * @package XML_RPC * @author Edd Dumbill <edd@usefulinc.com> * @author Stig Bakken <stig@php.net> * @author Martin Jansen <mj@php.net> * @author Daniel Convissor <danielc@php.net> * @copyright 1999-2001 Edd Dumbill, 2001-2005 The PHP Group * @version Release: 1.4.4 * @link http://pear.php.net/package/XML_RPC */class XML_RPC_Value extends XML_RPC_Base{ var $me = array(); var $mytype = 0; /** * @return void */ function XML_RPC_Value($val = -1, $type = '') { global $XML_RPC_Types; $this->me = array(); $this->mytype = 0; if ($val != -1 || $type != '') { if ($type == '') {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -