More tabs/to/spaces conversion, plus remove closing php tags as they are not consider...
[plcapi.git] / lib / xmlrpc.php
index fb94bf3..111e6b2 100644 (file)
 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
 // OF THE POSSIBILITY OF SUCH DAMAGE.\r
 \r
+require_once __DIR__ . "/phpxmlrpc.php";\r
 require_once __DIR__ . "/xmlrpc_client.php";\r
 require_once __DIR__ . "/xmlrpcresp.php";\r
 require_once __DIR__ . "/xmlrpcmsg.php";\r
 require_once __DIR__ . "/xmlrpcval.php";\r
 \r
-class Xmlrpc {\r
-\r
-    public $xmlrpcI4 = "i4";\r
-    public $xmlrpcInt = "int";\r
-    public $xmlrpcBoolean = "boolean";\r
-    public $xmlrpcDouble = "double";\r
-    public $xmlrpcString = "string";\r
-    public $xmlrpcDateTime = "dateTime.iso8601";\r
-    public $xmlrpcBase64 = "base64";\r
-    public $xmlrpcArray = "array";\r
-    public $xmlrpcStruct = "struct";\r
-    public $xmlrpcValue = "undefined";\r
-    public $xmlrpcNull = "null";\r
-\r
-    public $xmlrpcTypes;\r
-\r
-    public $xmlrpc_valid_parents = array(\r
-        'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT'),\r
-        'BOOLEAN' => array('VALUE'),\r
-        'I4' => array('VALUE'),\r
-        'INT' => array('VALUE'),\r
-        'STRING' => array('VALUE'),\r
-        'DOUBLE' => array('VALUE'),\r
-        'DATETIME.ISO8601' => array('VALUE'),\r
-        'BASE64' => array('VALUE'),\r
-        'MEMBER' => array('STRUCT'),\r
-        'NAME' => array('MEMBER'),\r
-        'DATA' => array('ARRAY'),\r
-        'ARRAY' => array('VALUE'),\r
-        'STRUCT' => array('VALUE'),\r
-        'PARAM' => array('PARAMS'),\r
-        'METHODNAME' => array('METHODCALL'),\r
-        'PARAMS' => array('METHODCALL', 'METHODRESPONSE'),\r
-        'FAULT' => array('METHODRESPONSE'),\r
-        'NIL' => array('VALUE'), // only used when extension activated\r
-        'EX:NIL' => array('VALUE') // only used when extension activated\r
-    );\r
-\r
-    // tables used for transcoding different charsets into us-ascii xml\r
-    public $xml_iso88591_Entities = array("in" => array(), "out" => array());\r
-\r
-    /// @todo add to iso table the characters from cp_1252 range, i.e. 128 to 159?\r
-    /// These will NOT be present in true ISO-8859-1, but will save the unwary\r
-    /// windows user from sending junk (though no luck when reciving them...)\r
-    /*\r
-    $GLOBALS['xml_cp1252_Entities']=array();\r
-    for ($i = 128; $i < 160; $i++)\r
-    {\r
-        $GLOBALS['xml_cp1252_Entities']['in'][] = chr($i);\r
-    }\r
-    $GLOBALS['xml_cp1252_Entities']['out'] = array(\r
-        '&#x20AC;', '?',        '&#x201A;', '&#x0192;',\r
-        '&#x201E;', '&#x2026;', '&#x2020;', '&#x2021;',\r
-        '&#x02C6;', '&#x2030;', '&#x0160;', '&#x2039;',\r
-        '&#x0152;', '?',        '&#x017D;', '?',\r
-        '?',        '&#x2018;', '&#x2019;', '&#x201C;',\r
-        '&#x201D;', '&#x2022;', '&#x2013;', '&#x2014;',\r
-        '&#x02DC;', '&#x2122;', '&#x0161;', '&#x203A;',\r
-        '&#x0153;', '?',        '&#x017E;', '&#x0178;'\r
-    );\r
-    */\r
-\r
-    public $xmlrpcerr = array(\r
-        'unknown_method'=>1,\r
-        'invalid_return'=>2,\r
-        'incorrect_params'=>3,\r
-        'introspect_unknown'=>4,\r
-        'http_error'=>5,\r
-        'no_data'=>6,\r
-        'no_ssl'=>7,\r
-        'curl_fail'=>8,\r
-        'invalid_request'=>15,\r
-        'no_curl'=>16,\r
-        'server_error'=>17,\r
-        'multicall_error'=>18,\r
-        'multicall_notstruct'=>9,\r
-        'multicall_nomethod'=>10,\r
-        'multicall_notstring'=>11,\r
-        'multicall_recursion'=>12,\r
-        'multicall_noparams'=>13,\r
-        'multicall_notarray'=>14,\r
-\r
-        'cannot_decompress'=>103,\r
-        'decompress_fail'=>104,\r
-        'dechunk_fail'=>105,\r
-        'server_cannot_decompress'=>106,\r
-        'server_decompress_fail'=>107\r
-    );\r
-\r
-    public $xmlrpcstr = array(\r
-        'unknown_method'=>'Unknown method',\r
-        'invalid_return'=>'Invalid return payload: enable debugging to examine incoming payload',\r
-        'incorrect_params'=>'Incorrect parameters passed to method',\r
-        'introspect_unknown'=>"Can't introspect: method unknown",\r
-        'http_error'=>"Didn't receive 200 OK from remote server.",\r
-        'no_data'=>'No data received from server.',\r
-        'no_ssl'=>'No SSL support compiled in.',\r
-        'curl_fail'=>'CURL error',\r
-        'invalid_request'=>'Invalid request payload',\r
-        'no_curl'=>'No CURL support compiled in.',\r
-        'server_error'=>'Internal server error',\r
-        'multicall_error'=>'Received from server invalid multicall response',\r
-        'multicall_notstruct'=>'system.multicall expected struct',\r
-        'multicall_nomethod'=>'missing methodName',\r
-        'multicall_notstring'=>'methodName is not a string',\r
-        'multicall_recursion'=>'recursive system.multicall forbidden',\r
-        'multicall_noparams'=>'missing params',\r
-        'multicall_notarray'=>'params is not an array',\r
-\r
-        'cannot_decompress'=>'Received from server compressed HTTP and cannot decompress',\r
-        'decompress_fail'=>'Received from server invalid compressed HTTP',\r
-        'dechunk_fail'=>'Received from server invalid chunked HTTP',\r
-        'server_cannot_decompress'=>'Received from client compressed HTTP request and cannot decompress',\r
-        'server_decompress_fail'=>'Received from client invalid compressed HTTP request'\r
-    );\r
-\r
-    // The charset encoding used by the server for received messages and\r
-    // by the client for received responses when received charset cannot be determined\r
-    // or is not supported\r
-    public $xmlrpc_defencoding = "UTF-8";\r
-\r
-    // The encoding used internally by PHP.\r
-    // String values received as xml will be converted to this, and php strings will be converted to xml\r
-    // as if having been coded with this\r
-    public $xmlrpc_internalencoding = "ISO-8859-1"; // TODO: maybe this would be better as UTF-8, or atleast configurable?\r
-\r
-    public $xmlrpcName = "XML-RPC for PHP";\r
-    public $xmlrpcVersion = "3.0.0.beta";\r
-\r
-    // let user errors start at 800\r
-    public $xmlrpcerruser = 800;\r
-    // let XML parse errors start at 100\r
-    public $xmlrpcerrxml = 100;\r
-\r
-    // set to TRUE to enable correct decoding of <NIL/> and <EX:NIL/> values\r
-    public $xmlrpc_null_extension = false;\r
-\r
-    // set to TRUE to enable encoding of php NULL values to <EX:NIL/> instead of <NIL/>\r
-    public $xmlrpc_null_apache_encoding = false;\r
-\r
-    public $xmlrpc_null_apache_encoding_ns = "http://ws.apache.org/xmlrpc/namespaces/extensions";\r
-\r
-    // used to store state during parsing\r
-    // quick explanation of components:\r
-    //   ac - used to accumulate values\r
-    //   isf - used to indicate a parsing fault (2) or xmlrpcresp fault (1)\r
-    //   isf_reason - used for storing xmlrpcresp fault string\r
-    //   lv - used to indicate "looking for a value": implements\r
-    //        the logic to allow values with no types to be strings\r
-    //   params - used to store parameters in method calls\r
-    //   method - used to store method name\r
-    //   stack - array with genealogy of xml elements names:\r
-    //           used to validate nesting of xmlrpc elements\r
-    public $_xh = null;\r
-\r
-    private static $instance = null;\r
-\r
-    private function __construct() {\r
-        $this->xmlrpcTypes = array(\r
-            $this->xmlrpcI4 => 1,\r
-            $this->xmlrpcInt => 1,\r
-            $this->xmlrpcBoolean => 1,\r
-            $this->xmlrpcDouble => 1,\r
-            $this->xmlrpcString => 1,\r
-            $this->xmlrpcDateTime => 1,\r
-            $this->xmlrpcBase64 => 1,\r
-            $this->xmlrpcArray => 2,\r
-            $this->xmlrpcStruct => 3,\r
-            $this->xmlrpcNull => 1\r
-        );\r
-\r
-        for($i = 0; $i < 32; $i++) {\r
-            $this->xml_iso88591_Entities["in"][] = chr($i);\r
-            $this->xml_iso88591_Entities["out"][] = "&#{$i};";\r
-        }\r
-\r
-        for($i = 160; $i < 256; $i++) {\r
-            $this->xml_iso88591_Entities["in"][] = chr($i);\r
-            $this->xml_iso88591_Entities["out"][] = "&#{$i};";\r
-        }\r
-    }\r
-\r
-    /**\r
-    * This class is singleton for performance reasons: this way the ASCII array needs to be done only once.\r
-    */\r
-    public static function instance() {\r
-        if(Xmlrpc::$instance === null) {\r
-            Xmlrpc::$instance = new Xmlrpc();\r
-        }\r
-\r
-        return Xmlrpc::$instance;\r
-    }\r
-}\r
-\r
-\r
 /**\r
  * Convert a string to the correct XML representation in a target charset\r
  * To help correct communication of non-ascii chars inside strings, regardless\r
@@ -250,7 +56,7 @@ class Xmlrpc {
  */\r
 function xmlrpc_encode_entitites($data, $src_encoding='', $dest_encoding='')\r
 {\r
-    $xmlrpc = Xmlrpc::instance();\r
+    $xmlrpc = Phpxmlrpc::instance();\r
     if ($src_encoding == '')\r
     {\r
         // lame, but we know no better...\r
@@ -383,7 +189,7 @@ for ($nn = 0; $nn < $ns; $nn++)
 /// xml parser handler function for opening element tags\r
 function xmlrpc_se($parser, $name, $attrs, $accept_single_vals=false)\r
 {\r
-    $xmlrpc = Xmlrpc::instance();\r
+    $xmlrpc = Phpxmlrpc::instance();\r
     // if invalid xmlrpc already detected, skip all processing\r
     if ($xmlrpc->_xh['isf'] < 2)\r
     {\r
@@ -538,7 +344,7 @@ function xmlrpc_se_any($parser, $name, $attrs)
 /// xml parser handler function for close element tags\r
 function xmlrpc_ee($parser, $name, $rebuild_xmlrpcvals = true)\r
 {\r
-    $xmlrpc = Xmlrpc::instance();\r
+    $xmlrpc = Phpxmlrpc::instance();\r
 \r
     if ($xmlrpc->_xh['isf'] < 2)\r
     {\r
@@ -755,7 +561,7 @@ function xmlrpc_ee_fast($parser, $name)
 /// xml parser handler function for character data\r
 function xmlrpc_cd($parser, $data)\r
 {\r
-    $xmlrpc = Xmlrpc::instance();\r
+    $xmlrpc = Phpxmlrpc::instance();\r
     // skip processing if xml fault already detected\r
     if ($xmlrpc->_xh['isf'] < 2)\r
     {\r
@@ -773,7 +579,7 @@ function xmlrpc_cd($parser, $data)
             // we always initialize the accumulator before starting parsing, anyway...\r
             //if(!@isset($xmlrpc->_xh['ac']))\r
             //{\r
-            // $xmlrpc->_xh['ac'] = '';\r
+            //    $xmlrpc->_xh['ac'] = '';\r
             //}\r
             $xmlrpc->_xh['ac'].=$data;\r
         }\r
@@ -784,7 +590,7 @@ function xmlrpc_cd($parser, $data)
 /// element start/end tag. In fact it only gets called on unknown entities...\r
 function xmlrpc_dh($parser, $data)\r
 {\r
-    $xmlrpc = Xmlrpc::instance();\r
+    $xmlrpc = Phpxmlrpc::instance();\r
     // skip processing if xml fault already detected\r
     if ($xmlrpc->_xh['isf'] < 2)\r
     {\r
@@ -793,7 +599,7 @@ function xmlrpc_dh($parser, $data)
             // G. Giunta 2006-08-25: useless change of 'lv' from 1 to 2\r
             //if($xmlrpc->_xh['lv']==1)\r
             //{\r
-            // $xmlrpc->_xh['lv']=2;\r
+            //    $xmlrpc->_xh['lv']=2;\r
             //}\r
             $xmlrpc->_xh['ac'].=$data;\r
         }\r
@@ -1002,12 +808,12 @@ else
  * @author Dan Libby (dan@libby.com)\r
  *\r
  * @param mixed $php_val the value to be converted into an xmlrpcval object\r
- * @param array $options       can include 'encode_php_objs', 'auto_dates', 'null_extension' or 'extension_api'\r
+ * @param array $options can include 'encode_php_objs', 'auto_dates', 'null_extension' or 'extension_api'\r
  * @return xmlrpcval\r
  */\r
 function php_xmlrpc_encode($php_val, $options=array())\r
 {\r
-    $xmlrpc = Xmlrpc::instance();\r
+    $xmlrpc = Phpxmlrpc::instance();\r
     $type = gettype($php_val);\r
     switch($type)\r
     {\r
@@ -1125,7 +931,7 @@ function php_xmlrpc_encode($php_val, $options=array())
  */\r
 function php_xmlrpc_decode_xml($xml_val, $options=array())\r
 {\r
-    $xmlrpc = Xmlrpc::instance();\r
+    $xmlrpc = Phpxmlrpc::instance();\r
 \r
     $xmlrpc->_xh = array();\r
     $xmlrpc->_xh['ac'] = '';\r
@@ -1268,7 +1074,7 @@ function decode_chunked($buffer)
  */\r
 function guess_encoding($httpheader='', $xmlchunk='', $encoding_prefs=null)\r
 {\r
-    $xmlrpc = Xmlrpc::instance();\r
+    $xmlrpc = Phpxmlrpc::instance();\r
 \r
     // discussion: see http://www.yale.edu/pclt/encoding/\r
     // 1 - test if encoding is specified in HTTP HEADERS\r
@@ -1381,5 +1187,3 @@ function is_valid_charset($encoding, $validlist)
         return false;\r
     }\r
 }\r
-\r
-?>
\ No newline at end of file