xmlrpc.inc
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· INC 代码 · 共 2,042 行 · 第 1/5 页
INC
2,042 行
return;
}
}
switch($name)
{
// optimize for speed switch cases: most common cases first
case 'VALUE':
/// @todo we could check for 2 VALUE elements inside a MEMBER or PARAM element
$GLOBALS['_xh']['vt']='value'; // indicator: no value found yet
$GLOBALS['_xh']['ac']='';
$GLOBALS['_xh']['lv']=1;
$GLOBALS['_xh']['php_class']=null;
break;
case 'I4':
case 'INT':
case 'STRING':
case 'BOOLEAN':
case 'DOUBLE':
case 'DATETIME.ISO8601':
case 'BASE64':
if ($GLOBALS['_xh']['vt']!='value')
{
//two data elements inside a value: an error occurred!
$GLOBALS['_xh']['isf'] = 2;
$GLOBALS['_xh']['isf_reason'] = "$name element following a {$GLOBALS['_xh']['vt']} element inside a single value";
return;
}
$GLOBALS['_xh']['ac']=''; // reset the accumulator
break;
case 'STRUCT':
case 'ARRAY':
if ($GLOBALS['_xh']['vt']!='value')
{
//two data elements inside a value: an error occurred!
$GLOBALS['_xh']['isf'] = 2;
$GLOBALS['_xh']['isf_reason'] = "$name element following a {$GLOBALS['_xh']['vt']} element inside a single value";
return;
}
// create an empty array to hold child values, and push it onto appropriate stack
$cur_val = array();
$cur_val['values'] = array();
$cur_val['type'] = $name;
// check for out-of-band information to rebuild php objs
// and in case it is found, save it
if (@isset($attrs['PHP_CLASS']))
{
$cur_val['php_class'] = $attrs['PHP_CLASS'];
}
$GLOBALS['_xh']['valuestack'][] = $cur_val;
$GLOBALS['_xh']['vt']='data'; // be prepared for a data element next
break;
case 'DATA':
if ($GLOBALS['_xh']['vt']!='data')
{
//two data elements inside a value: an error occurred!
$GLOBALS['_xh']['isf'] = 2;
$GLOBALS['_xh']['isf_reason'] = "found two data elements inside an array element";
return;
}
case 'METHODCALL':
case 'METHODRESPONSE':
case 'PARAMS':
// valid elements that add little to processing
break;
case 'METHODNAME':
case 'NAME':
/// @todo we could check for 2 NAME elements inside a MEMBER element
$GLOBALS['_xh']['ac']='';
break;
case 'FAULT':
$GLOBALS['_xh']['isf']=1;
break;
case 'MEMBER':
$GLOBALS['_xh']['valuestack'][count($GLOBALS['_xh']['valuestack'])-1]['name']=''; // set member name to null, in case we do not find in the xml later on
//$GLOBALS['_xh']['ac']='';
// Drop trough intentionally
case 'PARAM':
// clear value type, so we can check later if no value has been passed for this param/member
$GLOBALS['_xh']['vt']=null;
break;
case 'NIL':
if ($GLOBALS['xmlrpc_null_extension'])
{
if ($GLOBALS['_xh']['vt']!='value')
{
//two data elements inside a value: an error occurred!
$GLOBALS['_xh']['isf'] = 2;
$GLOBALS['_xh']['isf_reason'] = "$name element following a {$GLOBALS['_xh']['vt']} element inside a single value";
return;
}
$GLOBALS['_xh']['ac']=''; // reset the accumulator
break;
}
// we do not support the <NIL/> extension, so
// drop through intentionally
default:
/// INVALID ELEMENT: RAISE ISF so that it is later recognized!!!
$GLOBALS['_xh']['isf'] = 2;
$GLOBALS['_xh']['isf_reason'] = "found not-xmlrpc xml element $name";
break;
}
// Save current element name to stack, to validate nesting
$GLOBALS['_xh']['stack'][] = $name;
/// @todo optimization creep: move this inside the big switch() above
if($name!='VALUE')
{
$GLOBALS['_xh']['lv']=0;
}
}
}
/// Used in decoding xml chunks that might represent single xmlrpc values
function xmlrpc_se_any($parser, $name, $attrs)
{
xmlrpc_se($parser, $name, $attrs, true);
}
/// xml parser handler function for close element tags
function xmlrpc_ee($parser, $name, $rebuild_xmlrpcvals = true)
{
if ($GLOBALS['_xh']['isf'] < 2)
{
// push this element name from stack
// NB: if XML validates, correct opening/closing is guaranteed and
// we do not have to check for $name == $curr_elem.
// we also checked for proper nesting at start of elements...
$curr_elem = array_pop($GLOBALS['_xh']['stack']);
switch($name)
{
case 'VALUE':
// This if() detects if no scalar was inside <VALUE></VALUE>
if ($GLOBALS['_xh']['vt']=='value')
{
$GLOBALS['_xh']['value']=$GLOBALS['_xh']['ac'];
$GLOBALS['_xh']['vt']=$GLOBALS['xmlrpcString'];
}
if ($rebuild_xmlrpcvals)
{
// build the xmlrpc val out of the data received, and substitute it
$temp =& new xmlrpcval($GLOBALS['_xh']['value'], $GLOBALS['_xh']['vt']);
// in case we got info about underlying php class, save it
// in the object we're rebuilding
if (isset($GLOBALS['_xh']['php_class']))
$temp->_php_class = $GLOBALS['_xh']['php_class'];
// check if we are inside an array or struct:
// if value just built is inside an array, let's move it into array on the stack
$vscount = count($GLOBALS['_xh']['valuestack']);
if ($vscount && $GLOBALS['_xh']['valuestack'][$vscount-1]['type']=='ARRAY')
{
$GLOBALS['_xh']['valuestack'][$vscount-1]['values'][] = $temp;
}
else
{
$GLOBALS['_xh']['value'] = $temp;
}
}
else
{
/// @todo this needs to treat correctly php-serialized objects,
/// since std deserializing is done by php_xmlrpc_decode,
/// which we will not be calling...
if (isset($GLOBALS['_xh']['php_class']))
{
}
// check if we are inside an array or struct:
// if value just built is inside an array, let's move it into array on the stack
$vscount = count($GLOBALS['_xh']['valuestack']);
if ($vscount && $GLOBALS['_xh']['valuestack'][$vscount-1]['type']=='ARRAY')
{
$GLOBALS['_xh']['valuestack'][$vscount-1]['values'][] = $GLOBALS['_xh']['value'];
}
}
break;
case 'BOOLEAN':
case 'I4':
case 'INT':
case 'STRING':
case 'DOUBLE':
case 'DATETIME.ISO8601':
case 'BASE64':
$GLOBALS['_xh']['vt']=strtolower($name);
/// @todo: optimization creep - remove the if/elseif cycle below
/// since the case() in which we are already did that
if ($name=='STRING')
{
$GLOBALS['_xh']['value']=$GLOBALS['_xh']['ac'];
}
elseif ($name=='DATETIME.ISO8601')
{
if (!preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $GLOBALS['_xh']['ac']))
{
error_log('XML-RPC: invalid value received in DATETIME: '.$GLOBALS['_xh']['ac']);
}
$GLOBALS['_xh']['vt']=$GLOBALS['xmlrpcDateTime'];
$GLOBALS['_xh']['value']=$GLOBALS['_xh']['ac'];
}
elseif ($name=='BASE64')
{
/// @todo check for failure of base64 decoding / catch warnings
$GLOBALS['_xh']['value']=base64_decode($GLOBALS['_xh']['ac']);
}
elseif ($name=='BOOLEAN')
{
// special case here: we translate boolean 1 or 0 into PHP
// constants true or false.
// Strings 'true' and 'false' are accepted, even though the
// spec never mentions them (see eg. Blogger api docs)
// NB: this simple checks helps a lot sanitizing input, ie no
// security problems around here
if ($GLOBALS['_xh']['ac']=='1' || strcasecmp($GLOBALS['_xh']['ac'], 'true') == 0)
{
$GLOBALS['_xh']['value']=true;
}
else
{
// log if receiveing something strange, even though we set the value to false anyway
if ($GLOBALS['_xh']['ac']!='0' && strcasecmp($_xh[$parser]['ac'], 'false') != 0)
error_log('XML-RPC: invalid value received in BOOLEAN: '.$GLOBALS['_xh']['ac']);
$GLOBALS['_xh']['value']=false;
}
}
elseif ($name=='DOUBLE')
{
// we have a DOUBLE
// we must check that only 0123456789-.<space> are characters here
if (!preg_match('/^[+-]?[eE0123456789 \t.]+$/', $GLOBALS['_xh']['ac']))
{
/// @todo: find a better way of throwing an error
// than this!
error_log('XML-RPC: non numeric value received in DOUBLE: '.$GLOBALS['_xh']['ac']);
$GLOBALS['_xh']['value']='ERROR_NON_NUMERIC_FOUND';
}
else
{
// it's ok, add it on
$GLOBALS['_xh']['value']=(double)$GLOBALS['_xh']['ac'];
}
}
else
{
// we have an I4/INT
// we must check that only 0123456789-<space> are characters here
if (!preg_match('/^[+-]?[0123456789 \t]+$/', $GLOBALS['_xh']['ac']))
{
/// @todo find a better way of throwing an error
// than this!
error_log('XML-RPC: non numeric value received in INT: '.$GLOBALS['_xh']['ac']);
$GLOBALS['_xh']['value']='ERROR_NON_NUMERIC_FOUND';
}
else
{
// it's ok, add it on
$GLOBALS['_xh']['value']=(int)$GLOBALS['_xh']['ac'];
}
}
//$GLOBALS['_xh']['ac']=''; // is this necessary?
$GLOBALS['_xh']['lv']=3; // indicate we've found a value
break;
case 'NAME':
$GLOBALS['_xh']['valuestack'][count($GLOBALS['_xh']['valuestack'])-1]['name'] = $GLOBALS['_xh']['ac'];
break;
case 'MEMBER':
//$GLOBALS['_xh']['ac']=''; // is this necessary?
// add to array in the stack the last element built,
// unless no VALUE was found
if ($GLOBALS['_xh']['vt'])
{
$vscount = count($GLOBALS['_xh']['valuestack']);
$GLOBALS['_xh']['valuestack'][$vscount-1]['values'][$GLOBALS['_xh']['valuestack'][$vscount-1]['name']] = $GLOBALS['_xh']['value'];
} else
error_log('XML-RPC: missing VALUE inside STRUCT in received xml');
break;
case 'DATA':
//$GLOBALS['_xh']['ac']=''; // is this necessary?
$GLOBALS['_xh']['vt']=null; // reset this to check for 2 data elements in a row - even if they're empty
break;
case 'STRUCT':
case 'ARRAY':
// fetch out of stack array of values, and promote it to current value
$curr_val = array_pop($GLOBALS['_xh']['valuestack']);
$GLOBALS['_xh']['value'] = $curr_val['values'];
$GLOBALS['_xh']['vt']=strtolower($name);
if (isset($curr_val['php_class']))
{
$GLOBALS['_xh']['php_class'] = $curr_val['php_class'];
}
break;
case 'PARAM':
// add to array of params the current value,
// unless no VALUE was found
if ($GLOBALS['_xh']['vt'])
{
$GLOBALS['_xh']['params'][]=$GLOBALS['_xh']['value'];
$GLOBALS['_xh']['pt'][]=$GLOBALS['_xh']['vt'];
}
else
error_log('XML-RPC: missing VALUE inside PARAM in received xml');
break;
case 'METHODNAME':
$GLOBALS['_xh']['method']=preg_replace('/^[\n\r\t ]+/', '', $GLOBALS['_xh']['ac']);
break;
case 'NIL':
if ($GLOBALS['xmlrpc_null_extension'])
{
$GLOBALS['_xh']['vt']='null';
$GLOBALS['_xh']['value']=null;
$GLOBALS['_xh']['lv']=3;
break;
}
// drop through intentionally if nil extension not enabled
case 'PARAMS':
case 'FAULT':
case 'METHODCALL':
case 'METHORESPONSE':
break;
default:
// End of INVALID ELEMENT!
// shall we add an assert here for unreachable code???
break;
}
}
}
/// Used in decoding xmlrpc requests/responses without rebuilding xmlrpc values
function xmlrpc_ee_fast($parser, $name)
{
xmlrpc_ee($parser, $name, false);
}
/// xml parser handler function for character data
function xmlrpc_cd($parser, $data)
{
// skip processing if xml fault already detected
if ($GLOBALS['_xh']['isf'] < 2)
{
// "lookforvalue==3" means that we've found an entire value
// and should discard any further character data
if($GLOBALS['_xh']['lv']!=3)
{
// G. Giunta 2006-08-23: useless change of 'lv' from 1 to 2
//if($GLOBALS['_xh']['lv']==1)
//{
// if we've found text and we're just in a <value> then
// say we've found a value
//$GLOBALS['_xh']['lv']=2;
//}
// we always initialize the accumulator before starting parsing, anyway...
//if(!@isset($GLOBALS['_xh']['ac']))
//{
// $GLOBALS['_xh']['ac'] = '';
//}
$GLOBALS['_xh']['ac'].=$data;
}
}
}
/// xml parser handler function for 'other stuff', ie. not char data or
/// element start/end tag. In fact it only gets called on unknown entities...
function xmlrpc_dh($parser, $data)
{
// skip processing if xml fault already detected
if ($GLOBALS['_xh']['isf'] < 2)
{
if(substr($data, 0, 1) == '&' && substr($data, -1, 1) == ';')
{
// G. Giunta 2006-08-25: useless change of 'lv' from 1 to 2
//if($GLOBALS['_xh']['lv']==1)
//{
// $GLOBALS['_xh']['lv']=2;
//}
$GLOBALS['_xh']['ac'].=$data;
}
}
return true;
}
class xmlrpc_client
{
var $path;
var $server;
var $port=0;
var $method='http';
var $errno;
var $errstr;
var $debug=0;
var $username='';
var $password='';
var $authtype=1;
var $cert='';
var $certpass='';
var $cacert='';
var $cacertdir='';
var $key='';
var $keypass='';
var $verifypeer=true;
var $verifyhost=1;
var $no_multicall=false;
var $proxy='';
var $proxyport=0;
var $proxy_user='';
var $proxy_pass='';
var $proxy_authtype=1;
var $cookies=array();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?