⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlrpc.inc

📁 一个全功能的国外博客商业程序
💻 INC
📖 第 1 页 / 共 4 页
字号:
				if ($code < 32 || $code > 159)
					$character = ("&#".strval($code).";");
				break;
			}
			$escapeddata .= $character;
		}
		return $escapeddata;
	}

	function xmlrpc_se($parser, $name, $attrs)
	{
		global $_xh, $xmlrpcDateTime, $xmlrpcString;

		switch($name)
		{
			case 'STRUCT':
			case 'ARRAY':
				$_xh[$parser]['st'].='array(';
				$_xh[$parser]['cm']++;
				// this last line turns quoting off
				// this means if we get an empty array we'll
				// simply get a bit of whitespace in the eval
				$_xh[$parser]['qt']=0;
				break;
			case 'NAME':
				$_xh[$parser]['st'].='"';
				$_xh[$parser]['ac']='';
				break;
			case 'FAULT':
				$_xh[$parser]['isf']=1;
				break;
			case 'PARAM':
				$_xh[$parser]['st']='';
				break;
			case 'VALUE':
				$_xh[$parser]['st'].='new xmlrpcval(';
				$_xh[$parser]['vt']=$xmlrpcString;
				$_xh[$parser]['ac']='';
				$_xh[$parser]['qt']=0;
				$_xh[$parser]['lv']=1;
				// look for a value: if this is still 1 by the
				// time we reach the first data segment then the type is string
				// by implication and we need to add in a quote
				break;
			case 'I4':
			case 'INT':
			case 'STRING':
			case 'BOOLEAN':
			case 'DOUBLE':
			case 'DATETIME.ISO8601':
			case 'BASE64':
				$_xh[$parser]['ac']=''; // reset the accumulator

				if ($name=='DATETIME.ISO8601' || $name=='STRING')
				{
					$_xh[$parser]['qt']=1;
					if ($name=='DATETIME.ISO8601')
					{
						$_xh[$parser]['vt']=$xmlrpcDateTime;
					}
				}
				elseif ($name=='BASE64')
				{
					$_xh[$parser]['qt']=2;
				}
				else
				{
					// No quoting is required here -- but
					// at the end of the element we must check
					// for data format errors.
					$_xh[$parser]['qt']=0;
				}
				break;
			case 'MEMBER':
				$_xh[$parser]['ac']='';
				break;
			default:
				break;
		}

		if ($name!='VALUE')
		{
			$_xh[$parser]['lv']=0;
		}
	}

	function xmlrpc_ee($parser, $name)
	{
		global $_xh,$xmlrpcTypes,$xmlrpcString;

		switch($name)
		{
			case 'STRUCT':
			case 'ARRAY':
				if ($_xh[$parser]['cm'] && substr($_xh[$parser]['st'], -1) ==',')
				{
					$_xh[$parser]['st']=substr($_xh[$parser]['st'],0,-1);
				}
				$_xh[$parser]['st'].=')';
				$_xh[$parser]['vt']=strtolower($name);
				$_xh[$parser]['cm']--;
				break;
			case 'NAME':
				$_xh[$parser]['st'].= $_xh[$parser]['ac'] . '" => ';
				break;
			case 'BOOLEAN':
				// special case here: we translate boolean 1 or 0 into PHP
				// constants true or false
				// NB: this simple checks helps a lot sanitizing input, ie no
				// security problems around here
				if ($_xh[$parser]['ac']=='1')
				{
					$_xh[$parser]['ac']='true';
				}
				else
				{
					$_xh[$parser]['ac']='false';
				}
				$_xh[$parser]['vt']=strtolower($name);
				// Drop through intentionally.
			case 'I4':
			case 'INT':
			case 'STRING':
			case 'DOUBLE':
			case 'DATETIME.ISO8601':
			case 'BASE64':
				if ($_xh[$parser]['qt']==1)
				{
					// we use double quotes rather than single so backslashification works OK
					$_xh[$parser]['st'].='"'. $_xh[$parser]['ac'] . '"';
				}
				elseif ($_xh[$parser]['qt']==2)
				{
					$_xh[$parser]['st'].='base64_decode("'. $_xh[$parser]['ac'] . '")';
				}
				elseif ($name=='BOOLEAN')
				{
					$_xh[$parser]['st'].=$_xh[$parser]['ac'];
				}
				elseif ($name=='DOUBLE')
				{
					// we have a DOUBLE
					// we must check that only 0123456789-.<space> are characters here
					if (!ereg("^[+-]?[eE0123456789 \\t\\.]+$", $_xh[$parser]['ac']))
					{
						// TODO: find a better way of throwing an error
						// than this!
						error_log('XML-RPC: non numeric value received in DOUBLE: '.$_xh[$parser]['ac']);
						$_xh[$parser]['st'].="'ERROR_NON_NUMERIC_FOUND'";
					}
					else
					{
						// it's ok, add it on
						$_xh[$parser]['st'].=(double)$_xh[$parser]['ac'];
					}
				}
				else
				{
					// we have an I4/INT
					// we must check that only 0123456789-<space> are characters here
					if (!ereg("^[+-]?[0123456789 \\t]+$", $_xh[$parser]['ac']))
					{
						// TODO: find a better way of throwing an error
						// than this!
						error_log('XML-RPC: non numeric value received in INT: '.$_xh[$parser]['ac']);
						$_xh[$parser]['st'].="'ERROR_NON_NUMERIC_FOUND'";
					}
					else
					{
						// it's ok, add it on
						$_xh[$parser]['st'].=(int)$_xh[$parser]['ac'];
					}
				}
				$_xh[$parser]['ac']='';
				$_xh[$parser]['qt']=0;
				$_xh[$parser]['lv']=3; // indicate we've found a value
				break;
			case 'VALUE':
				// deal with a string value
				if (strlen($_xh[$parser]['ac'])>0 &&
					$_xh[$parser]['vt']==$xmlrpcString)
				{
					$_xh[$parser]['st'].='"'. $_xh[$parser]['ac'] . '"';
				}
				// This if() detects if no scalar was inside <VALUE></VALUE>
				// and pads an empty ''.
				if($_xh[$parser]['st'][strlen($_xh[$parser]['st'])-1] == '(')
				{
					$_xh[$parser]['st'].= '""';
				}
				// G. Giunta 2005/03/12 save some chars in the reconstruction of string vals...
				if ($_xh[$parser]['vt'] != $xmlrpcString)
					$_xh[$parser]['st'].=", '" . $_xh[$parser]['vt'] . "')";
				else
					$_xh[$parser]['st'].=")";
				if ($_xh[$parser]['cm'])
				{
					$_xh[$parser]['st'].=',';
				}
				break;
			case 'MEMBER':
				$_xh[$parser]['ac']='';
				$_xh[$parser]['qt']=0;
				break;
			case 'DATA':
				$_xh[$parser]['ac']='';
				$_xh[$parser]['qt']=0;
				break;
			case 'PARAM':
				$_xh[$parser]['params'][]=$_xh[$parser]['st'];
				break;
			case 'METHODNAME':
				$_xh[$parser]['method']=ereg_replace("^[\n\r\t ]+", '', $_xh[$parser]['ac']);
				break;
			// BOOLEAN HAS BEEN ENUMERATED ABOVE!
			/*case 'BOOLEAN':
				// special case here: we translate boolean 1 or 0 into PHP
				// constants true or false
				if ($_xh[$parser]['ac']=='1')
				{
					$_xh[$parser]['ac']='true';
				}
				else
				{
					$_xh[$parser]['ac']='false';
					$_xh[$parser]['vt']=strtolower($name);
				}
				break;*/
			default:
				break;
		}
		// if it's a valid type name, set the type
		if (isset($xmlrpcTypes[strtolower($name)]))
		{
			$_xh[$parser]['vt']=strtolower($name);
		}
	}

	function xmlrpc_cd($parser, $data)
	{
		global $_xh, $xmlrpc_backslash;

		//if (ereg("^[\n\r \t]+$", $data)) return;
		// print "adding [${data}]\n";

		if ($_xh[$parser]['lv']!=3)
		{
			// "lookforvalue==3" means that we've found an entire value
			// and should discard any further character data
			if ($_xh[$parser]['lv']==1)
			{
				// if we've found text and we're just in a <value> then
				// turn quoting on, as this will be a string
				$_xh[$parser]['qt']=1;
				// and say we've found a value
				$_xh[$parser]['lv']=2;
			}
			if(!@isset($_xh[$parser]['ac']))
			{
				$_xh[$parser]['ac'] = '';
			}
			$_xh[$parser]['ac'].=str_replace('$', '\$', str_replace('"', '\"', str_replace(chr(92),$xmlrpc_backslash, $data)));
		}
	}

	function xmlrpc_dh($parser, $data)
	{
		global $_xh, $xmlrpc_backslash;
		if (substr($data, 0, 1) == '&' && substr($data, -1, 1) == ';')
		{
			if ($_xh[$parser]['lv']==1)
			{
				$_xh[$parser]['qt']=1;
				$_xh[$parser]['lv']=2;
			}
			$_xh[$parser]['ac'].=str_replace('$', '\$', str_replace('"', '\"', str_replace(chr(92),$xmlrpc_backslash, $data)));
		}
	}

	class xmlrpc_client
	{
		var $path;
		var $server;
		var $port;
		var $errno;
		var $errstr;
		var $debug=0;
		var $username='';
		var $password='';
		var $cert='';
		var $certpass='';
		var $verifypeer=1;
		var $verifyhost=1;
		var $no_multicall=false;

		function xmlrpc_client($path, $server, $port=0)
		{
			$this->port=$port; $this->server=$server; $this->path=$path;
		}

		function setDebug($in)
		{
			if ($in)
			{
				$this->debug=1;
			}
			else
			{
				$this->debug=0;
			}
		}

		function setCredentials($u, $p)
		{
			$this->username=$u;
			$this->password=$p;
		}

		function setCertificate($cert, $certpass)
		{
			$this->cert = $cert;
			$this->certpass = $certpass;
		}

		function setSSLVerifyPeer($i)
		{
			$this->verifypeer = $i;
		}

		function setSSLVerifyHost($i)
		{
			$this->verifyhost = $i;
		}

		function send($msg, $timeout=0, $method='http')
		{
			if (is_array($msg))
			{
				// $msg is an array of xmlrpcmsg's
				return $this->multicall($msg, $timeout, $method);
			}

			// where msg is an xmlrpcmsg
			$msg->debug=$this->debug;

			if ($method == 'https')
			{
				return $this->sendPayloadHTTPS($msg,
				$this->server,
				$this->port, $timeout,
				$this->username, $this->password,
				$this->cert,
				$this->certpass);
			}
			else
			{
				return $this->sendPayloadHTTP10($msg, $this->server, $this->port,
				$timeout, $this->username, 
				$this->password);
			}
		}

		function sendPayloadHTTP10($msg, $server, $port, $timeout=0,$username='', $password='')
		{
			global $xmlrpcerr, $xmlrpcstr, $xmlrpcName, $xmlrpcVersion, $xmlrpc_defencoding;
			if ($port==0)
			{
				$port=80;
			}
			if($timeout>0)
			{
				$fp=@fsockopen($server, $port,$this->errno, $this->errstr, $timeout);
			}
			else
			{
				$fp=@fsockopen($server, $port,$this->errno, $this->errstr);
			}
			if ($fp)
			{
				if ($timeout>0 && function_exists('stream_set_timeout'))
					stream_set_timeout($fp, $timeout);
			}
			else
			{
				$this->errstr='Connect error';
				$r=new xmlrpcresp(0, $xmlrpcerr['http_error'],$xmlrpcstr['http_error']);
				return $r;
			}
			// 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\n" .
				"User-Agent: " . $xmlrpcName . " " . $xmlrpcVersion . "\r\n" .
				"Host: ". $server . "\r\n" .
				$credentials . 
				"Accept-Charset: " . $xmlrpc_defencoding . "\r\n" .
				"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';
				$r=new xmlrpcresp(0, $xmlrpcerr['http_error'], $xmlrpcstr['http_error']);
				return $r;
			}
			$resp=$msg->parseResponseFile($fp);
			fclose($fp);
			return $resp;
		}

		// contributed by Justin Miller <justin@voxel.net>
		// requires curl to be built into PHP
		function sendPayloadHTTPS($msg, $server, $port, $timeout=0,$username='', $password='', $cert='',$certpass='')
		{
			global $xmlrpcerr, $xmlrpcstr, $xmlrpcVersion, $xmlrpc_internalencoding;
			if ($port == 0)
			{
				$port = 443;
			}

			// Only create the payload if it was not created previously
			if(empty($msg->payload))
			{
				$msg->createPayload();
			}

			if (!function_exists('curl_init'))
			{
				$this->errstr='SSL unavailable on this install';
				$r=new xmlrpcresp(0, $xmlrpcerr['no_ssl'], $xmlrpcstr['no_ssl']);
				return $r;
			}

			$curl = curl_init('https://' . $server . ':' . $port . $this->path);

			curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
			// results into variable
			if ($this->debug)
			{
				curl_setopt($curl, CURLOPT_VERBOSE, 1);
			}
			curl_setopt($curl, CURLOPT_USERAGENT, 'PHP XMLRPC '.$xmlrpcVersion);
			// required for XMLRPC
			curl_setopt($curl, CURLOPT_POST, 1);
			// post the data
			curl_setopt($curl, CURLOPT_POSTFIELDS, $msg->payload);
			// the data
			curl_setopt($curl, CURLOPT_HEADER, 1);
			// return the header too
			curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/xml', 'Accept-Charset: '.$xmlrpc_internalencoding));
			// whether to verify remote host's cert
			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifypeer);
			// whether to verify cert's common name (CN); 0 for no, 1 to verify that it exists, and 2 to verify that it matches the hostname used
			curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost);
			// required for XMLRPC
			if ($timeout)
			{
				curl_setopt($curl, CURLOPT_TIMEOUT, $timeout == 1 ? 1 : $timeout - 1);
			}
			// timeout is borked
			if ($username && $password)
			{
				curl_setopt($curl, CURLOPT_USERPWD,"$username:$password");
			}
			// set auth stuff
			if ($cert)
			{
				curl_setopt($curl, CURLOPT_SSLCERT, $cert);
			}
			// set cert file
			if ($certpass)
			{
				curl_setopt($curl, CURLOPT_SSLCERTPASSWD,$certpass);
			}
			// set cert password

			$result = curl_exec($curl);

			if (!$result)
			{
				$this->errstr='no response';
				$resp=new xmlrpcresp(0, $xmlrpcerr['curl_fail'], $xmlrpcstr['curl_fail']. ': '. curl_error($curl));
				curl_close($curl);
			}
			else
			{
				curl_close($curl);
				$resp = $msg->parseResponse($result);
			}
			return $resp;
		}

		function multicall($msgs, $timeout=0, $method='http')
		{
			$results = false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -