📄 lib-xmlrpc.inc.php
字号:
<?php // $Revision: 2746 $
/************************************************************************/
/* phpAdsNew */
/* ========= */
/* */
/* Copyright (c) 1999,2000,2001 Edd Dumbill */
/* For more information visit: http://www.phpadsnew.com */
/************************************************************************/
/*********************************************************/
/* XML-RPC client code */
/*********************************************************/
// Copyright (c) 1999,2000,2002 Edd Dumbill.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// * Neither the name of the "XML-RPC for PHP" nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
// Disabled automatic loading of library.
// Niels Leenheer <niels@creatype.nl
/*
if (!function_exists('xml_parser_create')) {
// Win 32 fix. From: "Leo West" <lwest@imaginet.fr>
if($WINDIR) {
dl("php3_xml.dll");
} else {
dl("xml.so");
}
}
*/
// G. Giunta 2005/01/29: declare global these variables,
// so that xmlrpc.inc will work even if included from within a function
// NB: it will give warnings in PHP3, so we comment it out
// Milosch: Next round, maybe we should explicitly request these via $GLOBALS where used.
if (phpversion() >= '4')
{
global $xmlrpcI4;
global $xmlrpcInt;
global $xmlrpcDouble;
global $xmlrpcBoolean;
global $xmlrpcString;
global $xmlrpcDateTime;
global $xmlrpcBase64;
global $xmlrpcArray;
global $xmlrpcStruct;
global $xmlrpcTypes;
global $xmlrpc_valid_parents;
global $xmlEntities;
global $xmlrpcerr;
global $xmlrpcstr;
global $xmlrpc_defencoding;
global $xmlrpc_internalencoding;
global $xmlrpcName;
global $xmlrpcVersion;
global $xmlrpcerruser;
global $xmlrpcerrxml;
global $xmlrpc_backslash;
global $_xh;
}
$xmlrpcI4='i4';
$xmlrpcInt='int';
$xmlrpcBoolean='boolean';
$xmlrpcDouble='double';
$xmlrpcString='string';
$xmlrpcDateTime='dateTime.iso8601';
$xmlrpcBase64='base64';
$xmlrpcArray='array';
$xmlrpcStruct='struct';
$xmlrpcTypes=array(
$xmlrpcI4 => 1,
$xmlrpcInt => 1,
$xmlrpcBoolean => 1,
$xmlrpcString => 1,
$xmlrpcDouble => 1,
$xmlrpcDateTime => 1,
$xmlrpcBase64 => 1,
$xmlrpcArray => 2,
$xmlrpcStruct => 3
);
$xmlrpc_valid_parents = array(
'BOOLEAN' => array('VALUE'),
'I4' => array('VALUE'),
'INT' => array('VALUE'),
'STRING' => array('VALUE'),
'DOUBLE' => array('VALUE'),
'DATETIME.ISO8601' => array('VALUE'),
'BASE64' => array('VALUE'),
'ARRAY' => array('VALUE'),
'STRUCT' => array('VALUE'),
'PARAM' => array('PARAMS'),
'METHODNAME' => array('METHODCALL'),
'PARAMS' => array('METHODCALL', 'METHODRESPONSE'),
'MEMBER' => array('STRUCT'),
'NAME' => array('MEMBER'),
'DATA' => array('ARRAY'),
'FAULT' => array('METHODRESPONSE'),
'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT'),
);
$xmlEntities=array(
'amp' => '&',
'quot' => '"',
'lt' => '<',
'gt' => '>',
'apos' => "'"
);
$xmlrpcerr['unknown_method']=1;
$xmlrpcstr['unknown_method']='Unknown method';
$xmlrpcerr['invalid_return']=2;
$xmlrpcstr['invalid_return']='Invalid return payload: enable debugging to examine incoming payload';
$xmlrpcerr['incorrect_params']=3;
$xmlrpcstr['incorrect_params']='Incorrect parameters passed to method';
$xmlrpcerr['introspect_unknown']=4;
$xmlrpcstr['introspect_unknown']="Can't introspect: method unknown";
$xmlrpcerr['http_error']=5;
$xmlrpcstr['http_error']="Didn't receive 200 OK from remote server.";
$xmlrpcerr['no_data']=6;
$xmlrpcstr['no_data']='No data received from server.';
$xmlrpcerr['no_ssl']=7;
$xmlrpcstr['no_ssl']='No SSL support compiled in.';
$xmlrpcerr['curl_fail']=8;
$xmlrpcstr['curl_fail']='CURL error';
$xmlrpcerr['invalid_request']=15;
$xmlrpcstr['invalid_request']='Invalid request payload';
$xmlrpcerr['multicall_notstruct'] = 9;
$xmlrpcstr['multicall_notstruct'] = 'system.multicall expected struct';
$xmlrpcerr['multicall_nomethod'] = 10;
$xmlrpcstr['multicall_nomethod'] = 'missing methodName';
$xmlrpcerr['multicall_notstring'] = 11;
$xmlrpcstr['multicall_notstring'] = 'methodName is not a string';
$xmlrpcerr['multicall_recursion'] = 12;
$xmlrpcstr['multicall_recursion'] = 'recursive system.multicall forbidden';
$xmlrpcerr['multicall_noparams'] = 13;
$xmlrpcstr['multicall_noparams'] = 'missing params';
$xmlrpcerr['multicall_notarray'] = 14;
$xmlrpcstr['multicall_notarray'] = 'params is not an array';
// The charset encoding expected by the server for received messages and
// by the client for received responses
$xmlrpc_defencoding='UTF-8';
// The encoding used by PHP.
// String values received will be converted to this.
$xmlrpc_internalencoding='ISO-8859-1';
$xmlrpcName='XML-RPC for PHP';
$xmlrpcVersion='1.2';
// let user errors start at 800
$xmlrpcerruser=800;
// let XML parse errors start at 100
$xmlrpcerrxml=100;
// formulate backslashes for escaping regexp
$xmlrpc_backslash=chr(92).chr(92);
// used to store state during parsing
// quick explanation of components:
// ac - used to accumulate values
// isf - used to indicate a fault
// lv - used to indicate "looking for a value": implements
// the logic to allow values with no types to be strings
// params - used to store parameters in method calls
// method - used to store method name
// stack - array with genealogy of xml elements names:
// used to validate nesting of xmlrpc elements
$_xh=array();
/**
* To help correct communication of non-ascii chars inside strings, regardless
* of the charset used when sending requests, parsing them, sending responses
* and parsing responses, convert all non-ascii chars present in the message
* into their equivalent 'charset entity'. Charset entities enumerated this way
* are independent of the charset encoding used to transmit them, and all XML
* parsers are bound to understand them.
*/
function xmlrpc_entity_decode($string)
{
$top=split('&', $string);
$op='';
$i=0;
while($i<sizeof($top))
{
if (ereg("^([#a-zA-Z0-9]+);", $top[$i], $regs))
{
$op.=ereg_replace("^[#a-zA-Z0-9]+;",
xmlrpc_lookup_entity($regs[1]),
$top[$i]);
}
else
{
if ($i==0)
{
$op=$top[$i];
}
else
{
$op.='&' . $top[$i];
}
}
$i++;
}
return $op;
}
function xmlrpc_lookup_entity($ent)
{
global $xmlEntities;
if (isset($xmlEntities[strtolower($ent)]))
{
return $xmlEntities[strtolower($ent)];
}
if (ereg("^#([0-9]+)$", $ent, $regs))
{
return chr($regs[1]);
}
return '?';
}
/**
* These entities originate from HTML specs (1.1, proposed 2.0, etc),
* and are taken directly from php-4.3.1/ext/mbstring/html_entities.c.
* Until php provides functionality to translate these entities in its
* core library, use this function.
*/
function xmlrpc_html_entity_xlate($data = '')
{
$entities = array(
" " => " ",
"¡" => "¡",
"¢" => "¢",
"£" => "£",
"¤" => "¤",
"¥" => "¥",
"¦" => "¦",
"§" => "§",
"¨" => "¨",
"©" => "©",
"ª" => "ª",
"«" => "«",
"¬" => "¬",
"­" => "­",
"®" => "®",
"¯" => "¯",
"°" => "°",
"±" => "±",
"²" => "²",
"³" => "³",
"´" => "´",
"µ" => "µ",
"¶" => "¶",
"·" => "·",
"¸" => "¸",
"¹" => "¹",
"º" => "º",
"»" => "»",
"¼" => "¼",
"½" => "½",
"¾" => "¾",
"¿" => "¿",
"À" => "À",
"Á" => "Á",
"Â" => "Â",
"Ã" => "Ã",
"Ä" => "Ä",
"Å" => "Å",
"Æ" => "Æ",
"Ç" => "Ç",
"È" => "È",
"É" => "É",
"Ê" => "Ê",
"Ë" => "Ë",
"Ì" => "Ì",
"Í" => "Í",
"Î" => "Î",
"Ï" => "Ï",
"Ð" => "Ð",
"Ñ" => "Ñ",
"Ò" => "Ò",
"Ó" => "Ó",
"Ô" => "Ô",
"Õ" => "Õ",
"Ö" => "Ö",
"×" => "×",
"Ø" => "Ø",
"Ù" => "Ù",
"Ú" => "Ú",
"Û" => "Û",
"Ü" => "Ü",
"Ý" => "Ý",
"Þ" => "Þ",
"ß" => "ß",
"à" => "à",
"á" => "á",
"â" => "â",
"ã" => "ã",
"ä" => "ä",
"å" => "å",
"æ" => "æ",
"ç" => "ç",
"è" => "è",
"é" => "é",
"ê" => "ê",
"ë" => "ë",
"ì" => "ì",
"í" => "í",
"î" => "î",
"ï" => "ï",
"ð" => "ð",
"ñ" => "ñ",
"ò" => "ò",
"ó" => "ó",
"ô" => "ô",
"õ" => "õ",
"ö" => "ö",
"÷" => "÷",
"ø" => "ø",
"ù" => "ù",
"ú" => "ú",
"û" => "û",
"ü" => "ü",
"ý" => "ý",
"þ" => "þ",
"ÿ" => "ÿ",
"Œ" => "Œ",
"œ" => "œ",
"Š" => "Š",
"š" => "š",
"Ÿ" => "Ÿ",
"ƒ" => "ƒ",
"ˆ" => "ˆ",
"˜" => "˜",
"Α" => "Α",
"Β" => "Β",
"Γ" => "Γ",
"Δ" => "Δ",
"Ε" => "Ε",
"Ζ" => "Ζ",
"Η" => "Η",
"Θ" => "Θ",
"Ι" => "Ι",
"Κ" => "Κ",
"Λ" => "Λ",
"Μ" => "Μ",
"Ν" => "Ν",
"Ξ" => "Ξ",
"Ο" => "Ο",
"Π" => "Π",
"Ρ" => "Ρ",
"Σ" => "Σ",
"Τ" => "Τ",
"Υ" => "Υ",
"Φ" => "Φ",
"Χ" => "Χ",
"Ψ" => "Ψ",
"Ω" => "Ω",
"β" => "β",
"γ" => "γ",
"δ" => "δ",
"ε" => "ε",
"ζ" => "ζ",
"η" => "η",
"θ" => "θ",
"ι" => "ι",
"κ" => "κ",
"λ" => "λ",
"μ" => "μ",
"ν" => "ν",
"ξ" => "ξ",
"ο" => "ο",
"π" => "π",
"ρ" => "ρ",
"ς" => "ς",
"σ" => "σ",
"τ" => "τ",
"υ" => "υ",
"φ" => "φ",
"χ" => "χ",
"ψ" => "ψ",
"ω" => "ω",
"ϑ" => "ϑ",
"ϒ" => "ϒ",
"ϖ" => "ϖ",
" " => " ",
" " => " ",
" " => " ",
"‌" => "‌",
"‍" => "‍",
"‎" => "‎",
"‏" => "‏",
"–" => "–",
"—" => "—",
"‘" => "‘",
"’" => "’",
"‚" => "‚",
"“" => "“",
"”" => "”",
"„" => "„",
"†" => "†",
"‡" => "‡",
"•" => "•",
"…" => "…",
"‰" => "‰",
"′" => "′",
"″" => "″",
"‹" => "‹",
"›" => "›",
"‾" => "‾",
"⁄" => "⁄",
"€" => "€",
"℘" => "℘",
"ℑ" => "ℑ",
"ℜ" => "ℜ",
"™" => "™",
"ℵ" => "ℵ",
"←" => "←",
"↑" => "↑",
"→" => "→",
"↓" => "↓",
"↔" => "↔",
"↵" => "↵",
"⇐" => "⇐",
"⇑" => "⇑",
"⇒" => "⇒",
"⇓" => "⇓",
"⇔" => "⇔",
"∀" => "∀",
"∂" => "∂",
"∃" => "∃",
"∅" => "∅",
"∇" => "∇",
"∈" => "∈",
"∉" => "∉",
"∋" => "∋",
"∏" => "∏",
"∑" => "∑",
"−" => "−",
"∗" => "∗",
"√" => "√",
"∝" => "∝",
"∞" => "∞",
"∠" => "∠",
"∧" => "∧",
"∨" => "∨",
"∩" => "∩",
"∪" => "∪",
"∫" => "∫",
"∴" => "∴",
"∼" => "∼",
"≅" => "≅",
"≈" => "≈",
"≠" => "≠",
"≡" => "≡",
"≤" => "≤",
"≥" => "≥",
"⊂" => "⊂",
"⊃" => "⊃",
"⊄" => "⊄",
"⊆" => "⊆",
"⊇" => "⊇",
"⊕" => "⊕",
"⊗" => "⊗",
"⊥" => "⊥",
"⋅" => "⋅",
"⌈" => "⌈",
"⌉" => "⌉",
"⌊" => "⌊",
"⌋" => "⌋",
"⟨" => "〈",
"⟩" => "〉",
"◊" => "◊",
"♠" => "♠",
"♣" => "♣",
"♥" => "♥",
"♦" => "♦");
return strtr($data, $entities);
}
function xmlrpc_encode_entitites($data)
{
$length = strlen($data);
$escapeddata = "";
for($position = 0; $position < $length; $position++)
{
$character = substr($data, $position, 1);
$code = Ord($character);
switch($code) {
case 34:
$character = """;
break;
case 38:
$character = "&";
break;
case 39:
$character = "'";
break;
case 60:
$character = "<";
break;
case 62:
$character = ">";
break;
default:
if ($code < 32 || $code > 159)
$character = ("&#".strval($code).";");
break;
}
$escapeddata .= $character;
}
return $escapeddata;
}
function xmlrpc_se($parser, $name, $attrs)
{
global $_xh, $xmlrpcDateTime, $xmlrpcString, $xmlrpc_valid_parents;
// if invalid xmlrpc already detected, skip all processing
if ($_xh[$parser]['isf'] < 2)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -