OSDN Git Service

XML-RPC for PHP Unspecified PHP Code Execution Vulnerability
authorkimitake <kimitake@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Sat, 13 Aug 2005 07:25:03 +0000 (07:25 +0000)
committerkimitake <kimitake@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Sat, 13 Aug 2005 07:25:03 +0000 (07:25 +0000)
git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/nucleus-jp/trunk@109 1ca29b6e-896d-4ea0-84a5-967f57386b96

euc/nucleus/libs/xmlrpc.inc.php
euc/nucleus/libs/xmlrpcs.inc.php
euc/nucleus/xmlrpc/server.php
utf8/nucleus/libs/xmlrpc.inc.php
utf8/nucleus/libs/xmlrpcs.inc.php
utf8/nucleus/xmlrpc/server.php

index 4ea4bb0..873f38e 100755 (executable)
@@ -1,19 +1,10 @@
 <?php                                  // -*-c++-*-\r
-// by Edd Dumbill (C) 1999-2001\r
+// by Edd Dumbill (C) 1999-2002\r
 // <edd@usefulinc.com>\r
-// $Id: xmlrpc.inc.php,v 1.4 2005-03-16 08:10:35 kimitake Exp $\r
-// $NucleusJP: xmlrpc.inc.php,v 1.4 2005/03/08 06:49:33 kimitake Exp $\r
+// $Id: xmlrpc.inc.php,v 1.5 2005-08-13 07:20:34 kimitake Exp $\r
+// $NucleusJP: xmlrpc.inc.php,v 1.4.2.2 2005/07/03 05:16:44 kimitake Exp $\r
 \r
-/*\r
-       Modifications made for use with Nucleus:\r
-       \r
-       renamed methods:\r
-       xmlrpc_encode -> _xmlrpc_encode\r
-       xmlrpc_decode -> _xmlrpc_decode\r
-*/\r
-\r
-\r
-// Copyright (c) 1999,2000,2001 Edd Dumbill.\r
+// Copyright (c) 1999,2000,2002 Edd Dumbill.\r
 // All rights reserved.\r
 //\r
 // Redistribution and use in source and binary forms, with or without\r
 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
 // OF THE POSSIBILITY OF SUCH DAMAGE.\r
 \r
-if (!function_exists('xml_parser_create')) {\r
-// Win 32 fix. From: "Leo West" <lwest@imaginet.fr>\r
-       if($WINDIR) {\r
-               dl("php3_xml.dll");\r
-       } else {\r
-               dl("xml.so");\r
-       }\r
-}\r
-\r
-$xmlrpcI4="i4";\r
-$xmlrpcInt="int";\r
-$xmlrpcBoolean="boolean";\r
-$xmlrpcDouble="double";\r
-$xmlrpcString="string";\r
-$xmlrpcDateTime="dateTime.iso8601";\r
-$xmlrpcBase64="base64";\r
-$xmlrpcArray="array";\r
-$xmlrpcStruct="struct";\r
-\r
-\r
-$xmlrpcTypes=array($xmlrpcI4 => 1,\r
-                                  $xmlrpcInt => 1,\r
-                                  $xmlrpcBoolean => 1,\r
-                                  $xmlrpcString => 1,\r
-                                  $xmlrpcDouble => 1,\r
-                                  $xmlrpcDateTime => 1,\r
-                                  $xmlrpcBase64 => 1,\r
-                                  $xmlrpcArray => 2,\r
-                                  $xmlrpcStruct => 3);\r
-\r
-$xmlEntities=array(     "amp" => "&",\r
-                                                                        "quot" => '"',\r
-                                                                        "lt" => "<",\r
-                                                                        "gt" => ">",\r
-                                                                        "apos" => "'");\r
-\r
-$xmlrpcerr["unknown_method"]=1;\r
-$xmlrpcstr["unknown_method"]="Unknown method";\r
-$xmlrpcerr["invalid_return"]=2;\r
-$xmlrpcstr["invalid_return"]="Invalid return payload: enabling debugging to examine incoming payload";\r
-$xmlrpcerr["incorrect_params"]=3;\r
-$xmlrpcstr["incorrect_params"]="Incorrect parameters passed to method";\r
-$xmlrpcerr["introspect_unknown"]=4;\r
-$xmlrpcstr["introspect_unknown"]="Can't introspect: method unknown";\r
-$xmlrpcerr["http_error"]=5;\r
-$xmlrpcstr["http_error"]="Didn't receive 200 OK from remote server.";\r
-$xmlrpcerr["no_data"]=6;\r
-$xmlrpcstr["no_data"]="No data received from server.";\r
-$xmlrpcerr["no_ssl"]=7;\r
-$xmlrpcstr["no_ssl"]="No SSL support compiled in.";\r
-$xmlrpcerr["curl_fail"]=8;\r
-$xmlrpcstr["curl_fail"]="CURL error";\r
-\r
-$xmlrpc_defencoding="UTF-8";\r
-\r
-$xmlrpcName="XML-RPC for PHP";\r
-$xmlrpcVersion="1.02";\r
-\r
-// let user errors start at 800\r
-$xmlrpcerruser=800; \r
-// let XML parse errors start at 100\r
-$xmlrpcerrxml=100;\r
-\r
-// formulate backslashes for escaping regexp\r
-$xmlrpc_backslash=chr(92).chr(92);\r
-\r
-// used to store state during parsing\r
-// quick explanation of components:\r
-//   st - used to build up a string for evaluation\r
-//   ac - used to accumulate values\r
-//   qt - used to decide if quotes are needed for evaluation\r
-//   cm - used to denote struct or array (comma needed)\r
-//   isf - used to indicate a fault\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
-\r
-$_xh=array();\r
-\r
-function xmlrpc_entity_decode($string) {\r
-  $top=split("&", $string);\r
-  $op="";\r
-  $i=0; \r
-  while($i<sizeof($top)) {\r
-       if (ereg("^([#a-zA-Z0-9]+);", $top[$i], $regs)) {\r
-         $op.=ereg_replace("^[#a-zA-Z0-9]+;",\r
-                                               xmlrpc_lookup_entity($regs[1]),\r
-                                                                                       $top[$i]);\r
-       } else {\r
-         if ($i==0) \r
-               $op=$top[$i]; \r
-         else\r
-               $op.="&" . $top[$i];\r
-       }\r
-       $i++;\r
-  }\r
-  return $op;\r
-}\r
-\r
-function xmlrpc_lookup_entity($ent) {\r
-  global $xmlEntities;\r
-  \r
-  if (isset($xmlEntities[strtolower($ent)]))\r
-       return $xmlEntities[strtolower($ent)];\r
-  if (ereg("^#([0-9]+)$", $ent, $regs))\r
-       return chr($regs[1]);\r
-  return "?";\r
-}\r
-\r
-function xmlrpc_se($parser, $name, $attrs) {\r
-       global $_xh, $xmlrpcDateTime, $xmlrpcString;\r
-       \r
-       switch($name) {\r
-       case "STRUCT":\r
-       case "ARRAY":\r
-         $_xh[$parser]['st'].="array(";\r
-         $_xh[$parser]['cm']++;\r
-               // this last line turns quoting off\r
-               // this means if we get an empty array we'll \r
-               // simply get a bit of whitespace in the eval\r
-               $_xh[$parser]['qt']=0;\r
-         break;\r
-       case "NAME":\r
-         $_xh[$parser]['st'].="'"; $_xh[$parser]['ac']="";\r
-         break;\r
-       case "FAULT":\r
-         $_xh[$parser]['isf']=1;\r
-         break;\r
-       case "PARAM":\r
-         $_xh[$parser]['st']="";\r
-         break;\r
-       case "VALUE":\r
-         $_xh[$parser]['st'].="new xmlrpcval("; \r
-               $_xh[$parser]['vt']=$xmlrpcString;\r
-               $_xh[$parser]['ac']="";\r
-               $_xh[$parser]['qt']=0;\r
-         $_xh[$parser]['lv']=1;\r
-         // look for a value: if this is still 1 by the\r
-         // time we reach the first data segment then the type is string\r
-         // by implication and we need to add in a quote\r
-               break;\r
-\r
-       case "I4":\r
-       case "INT":\r
-       case "STRING":\r
-       case "BOOLEAN":\r
-       case "DOUBLE":\r
-       case "DATETIME.ISO8601":\r
-       case "BASE64":\r
-         $_xh[$parser]['ac']=""; // reset the accumulator\r
-\r
-         if ($name=="DATETIME.ISO8601" || $name=="STRING") {\r
-                       $_xh[$parser]['qt']=1; \r
-                       if ($name=="DATETIME.ISO8601")\r
-                               $_xh[$parser]['vt']=$xmlrpcDateTime;\r
-         } else if ($name=="BASE64") {\r
-                       $_xh[$parser]['qt']=2;\r
-               } else {\r
-                       // No quoting is required here -- but\r
-                       // at the end of the element we must check\r
-                       // for data format errors.\r
-                       $_xh[$parser]['qt']=0;\r
-         }\r
-               break;\r
-       case "MEMBER":\r
-               $_xh[$parser]['ac']="";\r
-         break;\r
-       default:\r
-               break;\r
+       if (!function_exists('xml_parser_create'))\r
+       {\r
+               // Win 32 fix. From: 'Leo West' <lwest@imaginet.fr>\r
+               if($WINDIR)\r
+               {\r
+                       dl('php3_xml.dll');\r
+               }\r
+               else\r
+               {\r
+                       dl('xml.so');\r
+               }\r
        }\r
 \r
-       if ($name!="VALUE") $_xh[$parser]['lv']=0;\r
-}\r
-\r
-function xmlrpc_ee($parser, $name) {\r
-       global $_xh,$xmlrpcTypes,$xmlrpcString;\r
-\r
-       switch($name) {\r
-       case "STRUCT":\r
-       case "ARRAY":\r
-         if ($_xh[$parser]['cm'] && substr($_xh[$parser]['st'], -1) ==',') {\r
-               $_xh[$parser]['st']=substr($_xh[$parser]['st'],0,-1);\r
-         }\r
-         $_xh[$parser]['st'].=")";     \r
-         $_xh[$parser]['vt']=strtolower($name);\r
-         $_xh[$parser]['cm']--;\r
-         break;\r
-       case "NAME":\r
-         $_xh[$parser]['st'].= $_xh[$parser]['ac'] . "' => ";\r
-         break;\r
-       case "BOOLEAN":\r
-               // special case here: we translate boolean 1 or 0 into PHP\r
-               // constants true or false\r
-               if ($_xh[$parser]['ac']=='1') \r
-                       $_xh[$parser]['ac']="true";\r
-               else \r
-                       $_xh[$parser]['ac']="false";\r
-               $_xh[$parser]['vt']=strtolower($name);\r
-               // Drop through intentionally.\r
-       case "I4":\r
-       case "INT":\r
-       case "STRING":\r
-       case "DOUBLE":\r
-       case "DATETIME.ISO8601":\r
-       case "BASE64":\r
-         if ($_xh[$parser]['qt']==1) {\r
-                       // we use double quotes rather than single so backslashification works OK\r
-                       $_xh[$parser]['st'].="\"". $_xh[$parser]['ac'] . "\""; \r
-               } else if ($_xh[$parser]['qt']==2) {\r
-                       $_xh[$parser]['st'].="base64_decode('". $_xh[$parser]['ac'] . "')"; \r
-               } else if ($name=="BOOLEAN") {\r
-                       $_xh[$parser]['st'].=$_xh[$parser]['ac'];\r
-               } else {\r
-                       // we have an I4, INT or a DOUBLE\r
-                       // we must check that only 0123456789-.<space> are characters here\r
-                       if (!ereg("^\-?[0123456789 \t\.]+$", $_xh[$parser]['ac'])) {\r
-                               // TODO: find a better way of throwing an error\r
-                               // than this!\r
-                               error_log("XML-RPC: non numeric value received in INT or DOUBLE");\r
-                               $_xh[$parser]['st'].="ERROR_NON_NUMERIC_FOUND";\r
-                       } else {\r
-                               // it's ok, add it on\r
-                               $_xh[$parser]['st'].=$_xh[$parser]['ac'];\r
+       // G. Giunta 2005/01/29: declare global these variables,\r
+       // so that xmlrpc.inc will work even if included from within a function\r
+       // NB: it will give warnings in PHP3, so we comment it out\r
+       // Milosch: Next round, maybe we should explicitly request these via $GLOBALS where used.\r
+       if (phpversion() >= '4')\r
+       {\r
+               global $xmlrpcI4;\r
+               global $xmlrpcInt;\r
+               global $xmlrpcDouble;\r
+               global $xmlrpcString;\r
+               global $xmlrpcDateTime;\r
+               global $xmlrpcBase64;\r
+               global $xmlrpcArray;\r
+               global $xmlrpcStruct;\r
+\r
+               global $xmlrpcTypes;\r
+               global $xmlEntities;\r
+               global $xmlrpcerr;\r
+               global $xmlrpcstr;\r
+               global $xmlrpc_defencoding;\r
+               global $xmlrpc_internalencoding;\r
+               global $xmlrpcName;\r
+               global $xmlrpcVersion;\r
+               global $xmlrpcerruser;\r
+               global $xmlrpcerrxml;\r
+               global $xmlrpc_backslash;\r
+               global $_xh;\r
+       }\r
+       $xmlrpcI4='i4';\r
+       $xmlrpcInt='int';\r
+       $xmlrpcBoolean='boolean';\r
+       $xmlrpcDouble='double';\r
+       $xmlrpcString='string';\r
+       $xmlrpcDateTime='dateTime.iso8601';\r
+       $xmlrpcBase64='base64';\r
+       $xmlrpcArray='array';\r
+       $xmlrpcStruct='struct';\r
+\r
+       $xmlrpcTypes=array(\r
+               $xmlrpcI4       => 1,\r
+               $xmlrpcInt      => 1,\r
+               $xmlrpcBoolean  => 1,\r
+               $xmlrpcString   => 1,\r
+               $xmlrpcDouble   => 1,\r
+               $xmlrpcDateTime => 1,\r
+               $xmlrpcBase64   => 1,\r
+               $xmlrpcArray    => 2,\r
+               $xmlrpcStruct   => 3\r
+       );\r
+\r
+       $xmlEntities=array(\r
+               'amp'  => '&',\r
+               'quot' => '"',\r
+               'lt'   => '<',\r
+               'gt'   => '>',\r
+               'apos' => "'"\r
+       );\r
+\r
+       $xmlrpcerr['unknown_method']=1;\r
+       $xmlrpcstr['unknown_method']='Unknown method';\r
+       $xmlrpcerr['invalid_return']=2;\r
+       $xmlrpcstr['invalid_return']='Invalid return payload: enable debugging to examine incoming payload';\r
+       $xmlrpcerr['incorrect_params']=3;\r
+       $xmlrpcstr['incorrect_params']='Incorrect parameters passed to method';\r
+       $xmlrpcerr['introspect_unknown']=4;\r
+       $xmlrpcstr['introspect_unknown']="Can't introspect: method unknown";\r
+       $xmlrpcerr['http_error']=5;\r
+       $xmlrpcstr['http_error']="Didn't receive 200 OK from remote server.";\r
+       $xmlrpcerr['no_data']=6;\r
+       $xmlrpcstr['no_data']='No data received from server.';\r
+       $xmlrpcerr['no_ssl']=7;\r
+       $xmlrpcstr['no_ssl']='No SSL support compiled in.';\r
+       $xmlrpcerr['curl_fail']=8;\r
+       $xmlrpcstr['curl_fail']='CURL error';\r
+\r
+\r
+       $xmlrpcerr['multicall_notstruct'] = 9;\r
+       $xmlrpcstr['multicall_notstruct'] = 'system.multicall expected struct';\r
+       $xmlrpcerr['multicall_nomethod']  = 10;\r
+       $xmlrpcstr['multicall_nomethod']  = 'missing methodName';\r
+       $xmlrpcerr['multicall_notstring'] = 11;\r
+       $xmlrpcstr['multicall_notstring'] = 'methodName is not a string';\r
+       $xmlrpcerr['multicall_recursion'] = 12;\r
+       $xmlrpcstr['multicall_recursion'] = 'recursive system.multicall forbidden';\r
+       $xmlrpcerr['multicall_noparams']  = 13;\r
+       $xmlrpcstr['multicall_noparams']  = 'missing params';\r
+       $xmlrpcerr['multicall_notarray']  = 14;\r
+       $xmlrpcstr['multicall_notarray']  = 'params is not an array';\r
+\r
+       // The charset encoding expected by the server for received messages and\r
+       // by the client for received responses\r
+       $xmlrpc_defencoding='UTF-8';\r
+       // The encoding used by PHP.\r
+       // String values received will be converted to this.\r
+       $xmlrpc_internalencoding='ISO-8859-1';\r
+\r
+       $xmlrpcName='XML-RPC for PHP';\r
+       $xmlrpcVersion='1.1.1';\r
+\r
+       // let user errors start at 800\r
+       $xmlrpcerruser=800;\r
+       // let XML parse errors start at 100\r
+       $xmlrpcerrxml=100;\r
+\r
+       // formulate backslashes for escaping regexp\r
+       $xmlrpc_backslash=chr(92).chr(92);\r
+\r
+       // used to store state during parsing\r
+       // quick explanation of components:\r
+       //   st - used to build up a string for evaluation\r
+       //   ac - used to accumulate values\r
+       //   qt - used to decide if quotes are needed for evaluation\r
+       //   cm - used to denote struct or array (comma needed)\r
+       //   isf - used to indicate a fault\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
+\r
+       $_xh=array();\r
+\r
+       /**\r
+       * To help correct communication of non-ascii chars inside strings, regardless\r
+       * of the charset used when sending requests, parsing them, sending responses\r
+       * and parsing responses, convert all non-ascii chars present in the message\r
+       * into their equivalent 'charset entity'. Charset entities enumerated this way\r
+       * are independent of the charset encoding used to transmit them, and all XML\r
+       * parsers are bound to understand them.\r
+       */\r
+       function xmlrpc_entity_decode($string)\r
+       {\r
+               $top=split('&', $string);\r
+               $op='';\r
+               $i=0;\r
+               while($i<sizeof($top))\r
+               {\r
+                       if (ereg("^([#a-zA-Z0-9]+);", $top[$i], $regs))\r
+                       {\r
+                               $op.=ereg_replace("^[#a-zA-Z0-9]+;",\r
+                               xmlrpc_lookup_entity($regs[1]),\r
+                               $top[$i]);\r
                        }\r
+                       else\r
+                       {\r
+                               if ($i==0)\r
+                               {\r
+                                       $op=$top[$i];\r
+                               }\r
+                               else\r
+                               {\r
+                                       $op.='&' . $top[$i];\r
+                               }\r
+                       }\r
+                       $i++;\r
                }\r
-               $_xh[$parser]['ac']=""; $_xh[$parser]['qt']=0;\r
-               $_xh[$parser]['lv']=3; // indicate we've found a value\r
-         break;\r
-       case "VALUE":\r
-               // deal with a string value\r
-               if (strlen($_xh[$parser]['ac'])>0 &&\r
-                               $_xh[$parser]['vt']==$xmlrpcString) {\r
-                       $_xh[$parser]['st'].="\"". $_xh[$parser]['ac'] . "\""; \r
+               return $op;\r
+       }\r
+\r
+       function xmlrpc_lookup_entity($ent)\r
+       {\r
+               global $xmlEntities;\r
+\r
+               if (isset($xmlEntities[strtolower($ent)]))\r
+               {\r
+                       return $xmlEntities[strtolower($ent)];\r
                }\r
-               // This if() detects if no scalar was inside <VALUE></VALUE>\r
-               // and pads an empty "".\r
-               if($_xh[$parser]['st'][strlen($_xh[$parser]['st'])-1] == '(') {\r
-                       $_xh[$parser]['st'].= '""';\r
+               if (ereg("^#([0-9]+)$", $ent, $regs))\r
+               {\r
+                       return chr($regs[1]);\r
                }\r
-               $_xh[$parser]['st'].=", '" . $_xh[$parser]['vt'] . "')";\r
-               if ($_xh[$parser]['cm']) $_xh[$parser]['st'].=",";\r
-               break;\r
-       case "MEMBER":\r
-         $_xh[$parser]['ac']=""; $_xh[$parser]['qt']=0;\r
-        break;\r
-       case "DATA":\r
-         $_xh[$parser]['ac']=""; $_xh[$parser]['qt']=0;\r
-         break;\r
-       case "PARAM":\r
-         $_xh[$parser]['params'][]=$_xh[$parser]['st'];\r
-         break;\r
-       case "METHODNAME":\r
-         $_xh[$parser]['method']=ereg_replace("^[\n\r\t ]+", "", \r
-                                                                                                                                                                $_xh[$parser]['ac']);\r
-               break;\r
-       case "BOOLEAN":\r
-               // special case here: we translate boolean 1 or 0 into PHP\r
-               // constants true or false\r
-               if ($_xh[$parser]['ac']=='1') \r
-                       $_xh[$parser]['ac']="true";\r
-               else \r
-                       $_xh[$parser]['ac']="false";\r
-               $_xh[$parser]['vt']=strtolower($name);\r
-               break;\r
-       default:\r
-               break;\r
+               return '?';\r
        }\r
-       // if it's a valid type name, set the type\r
-       if (isset($xmlrpcTypes[strtolower($name)])) {\r
-               $_xh[$parser]['vt']=strtolower($name);\r
+\r
+       /**\r
+        * These entities originate from HTML specs (1.1, proposed 2.0, etc),\r
+        * and are taken directly from php-4.3.1/ext/mbstring/html_entities.c.\r
+        * Until php provides functionality to translate these entities in its\r
+        * core library, use this function.\r
+        */\r
+       function xmlrpc_html_entity_xlate($data = '')\r
+       {\r
+               $entities = array(\r
+                       "&nbsp;" => "&#160;",\r
+                       "&iexcl;" => "&#161;",\r
+                       "&cent;" => "&#162;",\r
+                       "&pound;" => "&#163;",\r
+                       "&curren;" => "&#164;",\r
+                       "&yen;" => "&#165;",\r
+                       "&brvbar;" => "&#166;",\r
+                       "&sect;" => "&#167;",\r
+                       "&uml;" => "&#168;",\r
+                       "&copy;" => "&#169;",\r
+                       "&ordf;" => "&#170;",\r
+                       "&laquo;" => "&#171;",\r
+                       "&not;" => "&#172;",\r
+                       "&shy;" => "&#173;",\r
+                       "&reg;" => "&#174;",\r
+                       "&macr;" => "&#175;",\r
+                       "&deg;" => "&#176;",\r
+                       "&plusmn;" => "&#177;",\r
+                       "&sup2;" => "&#178;",\r
+                       "&sup3;" => "&#179;",\r
+                       "&acute;" => "&#180;",\r
+                       "&micro;" => "&#181;",\r
+                       "&para;" => "&#182;",\r
+                       "&middot;" => "&#183;",\r
+                       "&cedil;" => "&#184;",\r
+                       "&sup1;" => "&#185;",\r
+                       "&ordm;" => "&#186;",\r
+                       "&raquo;" => "&#187;",\r
+                       "&frac14;" => "&#188;",\r
+                       "&frac12;" => "&#189;",\r
+                       "&frac34;" => "&#190;",\r
+                       "&iquest;" => "&#191;",\r
+                       "&Agrave;" => "&#192;",\r
+                       "&Aacute;" => "&#193;",\r
+                       "&Acirc;" => "&#194;",\r
+                       "&Atilde;" => "&#195;",\r
+                       "&Auml;" => "&#196;",\r
+                       "&Aring;" => "&#197;",\r
+                       "&AElig;" => "&#198;",\r
+                       "&Ccedil;" => "&#199;",\r
+                       "&Egrave;" => "&#200;",\r
+                       "&Eacute;" => "&#201;",\r
+                       "&Ecirc;" => "&#202;",\r
+                       "&Euml;" => "&#203;",\r
+                       "&Igrave;" => "&#204;",\r
+                       "&Iacute;" => "&#205;",\r
+                       "&Icirc;" => "&#206;",\r
+                       "&Iuml;" => "&#207;",\r
+                       "&ETH;" => "&#208;",\r
+                       "&Ntilde;" => "&#209;",\r
+                       "&Ograve;" => "&#210;",\r
+                       "&Oacute;" => "&#211;",\r
+                       "&Ocirc;" => "&#212;",\r
+                       "&Otilde;" => "&#213;",\r
+                       "&Ouml;" => "&#214;",\r
+                       "&times;" => "&#215;",\r
+                       "&Oslash;" => "&#216;",\r
+                       "&Ugrave;" => "&#217;",\r
+                       "&Uacute;" => "&#218;",\r
+                       "&Ucirc;" => "&#219;",\r
+                       "&Uuml;" => "&#220;",\r
+                       "&Yacute;" => "&#221;",\r
+                       "&THORN;" => "&#222;",\r
+                       "&szlig;" => "&#223;",\r
+                       "&agrave;" => "&#224;",\r
+                       "&aacute;" => "&#225;",\r
+                       "&acirc;" => "&#226;",\r
+                       "&atilde;" => "&#227;",\r
+                       "&auml;" => "&#228;",\r
+                       "&aring;" => "&#229;",\r
+                       "&aelig;" => "&#230;",\r
+                       "&ccedil;" => "&#231;",\r
+                       "&egrave;" => "&#232;",\r
+                       "&eacute;" => "&#233;",\r
+                       "&ecirc;" => "&#234;",\r
+                       "&euml;" => "&#235;",\r
+                       "&igrave;" => "&#236;",\r
+                       "&iacute;" => "&#237;",\r
+                       "&icirc;" => "&#238;",\r
+                       "&iuml;" => "&#239;",\r
+                       "&eth;" => "&#240;",\r
+                       "&ntilde;" => "&#241;",\r
+                       "&ograve;" => "&#242;",\r
+                       "&oacute;" => "&#243;",\r
+                       "&ocirc;" => "&#244;",\r
+                       "&otilde;" => "&#245;",\r
+                       "&ouml;" => "&#246;",\r
+                       "&divide;" => "&#247;",\r
+                       "&oslash;" => "&#248;",\r
+                       "&ugrave;" => "&#249;",\r
+                       "&uacute;" => "&#250;",\r
+                       "&ucirc;" => "&#251;",\r
+                       "&uuml;" => "&#252;",\r
+                       "&yacute;" => "&#253;",\r
+                       "&thorn;" => "&#254;",\r
+                       "&yuml;" => "&#255;",\r
+                       "&OElig;" => "&#338;",\r
+                       "&oelig;" => "&#339;",\r
+                       "&Scaron;" => "&#352;",\r
+                       "&scaron;" => "&#353;",\r
+                       "&Yuml;" => "&#376;",\r
+                       "&fnof;" => "&#402;",\r
+                       "&circ;" => "&#710;",\r
+                       "&tilde;" => "&#732;",\r
+                       "&Alpha;" => "&#913;",\r
+                       "&Beta;" => "&#914;",\r
+                       "&Gamma;" => "&#915;",\r
+                       "&Delta;" => "&#916;",\r
+                       "&Epsilon;" => "&#917;",\r
+                       "&Zeta;" => "&#918;",\r
+                       "&Eta;" => "&#919;",\r
+                       "&Theta;" => "&#920;",\r
+                       "&Iota;" => "&#921;",\r
+                       "&Kappa;" => "&#922;",\r
+                       "&Lambda;" => "&#923;",\r
+                       "&Mu;" => "&#924;",\r
+                       "&Nu;" => "&#925;",\r
+                       "&Xi;" => "&#926;",\r
+                       "&Omicron;" => "&#927;",\r
+                       "&Pi;" => "&#928;",\r
+                       "&Rho;" => "&#929;",\r
+                       "&Sigma;" => "&#931;",\r
+                       "&Tau;" => "&#932;",\r
+                       "&Upsilon;" => "&#933;",\r
+                       "&Phi;" => "&#934;",\r
+                       "&Chi;" => "&#935;",\r
+                       "&Psi;" => "&#936;",\r
+                       "&Omega;" => "&#937;",\r
+                       "&beta;" => "&#946;",\r
+                       "&gamma;" => "&#947;",\r
+                       "&delta;" => "&#948;",\r
+                       "&epsilon;" => "&#949;",\r
+                       "&zeta;" => "&#950;",\r
+                       "&eta;" => "&#951;",\r
+                       "&theta;" => "&#952;",\r
+                       "&iota;" => "&#953;",\r
+                       "&kappa;" => "&#954;",\r
+                       "&lambda;" => "&#955;",\r
+                       "&mu;" => "&#956;",\r
+                       "&nu;" => "&#957;",\r
+                       "&xi;" => "&#958;",\r
+                       "&omicron;" => "&#959;",\r
+                       "&pi;" => "&#960;",\r
+                       "&rho;" => "&#961;",\r
+                       "&sigmaf;" => "&#962;",\r
+                       "&sigma;" => "&#963;",\r
+                       "&tau;" => "&#964;",\r
+                       "&upsilon;" => "&#965;",\r
+                       "&phi;" => "&#966;",\r
+                       "&chi;" => "&#967;",\r
+                       "&psi;" => "&#968;",\r
+                       "&omega;" => "&#969;",\r
+                       "&thetasym;" => "&#977;",\r
+                       "&upsih;" => "&#978;",\r
+                       "&piv;" => "&#982;",\r
+                       "&ensp;" => "&#8194;",\r
+                       "&emsp;" => "&#8195;",\r
+                       "&thinsp;" => "&#8201;",\r
+                       "&zwnj;" => "&#8204;",\r
+                       "&zwj;" => "&#8205;",\r
+                       "&lrm;" => "&#8206;",\r
+                       "&rlm;" => "&#8207;",\r
+                       "&ndash;" => "&#8211;",\r
+                       "&mdash;" => "&#8212;",\r
+                       "&lsquo;" => "&#8216;",\r
+                       "&rsquo;" => "&#8217;",\r
+                       "&sbquo;" => "&#8218;",\r
+                       "&ldquo;" => "&#8220;",\r
+                       "&rdquo;" => "&#8221;",\r
+                       "&bdquo;" => "&#8222;",\r
+                       "&dagger;" => "&#8224;",\r
+                       "&Dagger;" => "&#8225;",\r
+                       "&bull;" => "&#8226;",\r
+                       "&hellip;" => "&#8230;",\r
+                       "&permil;" => "&#8240;",\r
+                       "&prime;" => "&#8242;",\r
+                       "&Prime;" => "&#8243;",\r
+                       "&lsaquo;" => "&#8249;",\r
+                       "&rsaquo;" => "&#8250;",\r
+                       "&oline;" => "&#8254;",\r
+                       "&frasl;" => "&#8260;",\r
+                       "&euro;" => "&#8364;",\r
+                       "&weierp;" => "&#8472;",\r
+                       "&image;" => "&#8465;",\r
+                       "&real;" => "&#8476;",\r
+                       "&trade;" => "&#8482;",\r
+                       "&alefsym;" => "&#8501;",\r
+                       "&larr;" => "&#8592;",\r
+                       "&uarr;" => "&#8593;",\r
+                       "&rarr;" => "&#8594;",\r
+                       "&darr;" => "&#8595;",\r
+                       "&harr;" => "&#8596;",\r
+                       "&crarr;" => "&#8629;",\r
+                       "&lArr;" => "&#8656;",\r
+                       "&uArr;" => "&#8657;",\r
+                       "&rArr;" => "&#8658;",\r
+                       "&dArr;" => "&#8659;",\r
+                       "&hArr;" => "&#8660;",\r
+                       "&forall;" => "&#8704;",\r
+                       "&part;" => "&#8706;",\r
+                       "&exist;" => "&#8707;",\r
+                       "&empty;" => "&#8709;",\r
+                       "&nabla;" => "&#8711;",\r
+                       "&isin;" => "&#8712;",\r
+                       "&notin;" => "&#8713;",\r
+                       "&ni;" => "&#8715;",\r
+                       "&prod;" => "&#8719;",\r
+                       "&sum;" => "&#8721;",\r
+                       "&minus;" => "&#8722;",\r
+                       "&lowast;" => "&#8727;",\r
+                       "&radic;" => "&#8730;",\r
+                       "&prop;" => "&#8733;",\r
+                       "&infin;" => "&#8734;",\r
+                       "&ang;" => "&#8736;",\r
+                       "&and;" => "&#8743;",\r
+                       "&or;" => "&#8744;",\r
+                       "&cap;" => "&#8745;",\r
+                       "&cup;" => "&#8746;",\r
+                       "&int;" => "&#8747;",\r
+                       "&there4;" => "&#8756;",\r
+                       "&sim;" => "&#8764;",\r
+                       "&cong;" => "&#8773;",\r
+                       "&asymp;" => "&#8776;",\r
+                       "&ne;" => "&#8800;",\r
+                       "&equiv;" => "&#8801;",\r
+                       "&le;" => "&#8804;",\r
+                       "&ge;" => "&#8805;",\r
+                       "&sub;" => "&#8834;",\r
+                       "&sup;" => "&#8835;",\r
+                       "&nsub;" => "&#8836;",\r
+                       "&sube;" => "&#8838;",\r
+                       "&supe;" => "&#8839;",\r
+                       "&oplus;" => "&#8853;",\r
+                       "&otimes;" => "&#8855;",\r
+                       "&perp;" => "&#8869;",\r
+                       "&sdot;" => "&#8901;",\r
+                       "&lceil;" => "&#8968;",\r
+                       "&rceil;" => "&#8969;",\r
+                       "&lfloor;" => "&#8970;",\r
+                       "&rfloor;" => "&#8971;",\r
+                       "&lang;" => "&#9001;",\r
+                       "&rang;" => "&#9002;",\r
+                       "&loz;" => "&#9674;",\r
+                       "&spades;" => "&#9824;",\r
+                       "&clubs;" => "&#9827;",\r
+                       "&hearts;" => "&#9829;",\r
+                       "&diams;" => "&#9830;");\r
+               return strtr($data, $entities);\r
        }\r
-       \r
-}\r
-\r
-function xmlrpc_cd($parser, $data)\r
-{      \r
-  global $_xh, $xmlrpc_backslash;\r
-\r
-  //if (ereg("^[\n\r \t]+$", $data)) return;\r
-  // print "adding [${data}]\n";\r
-\r
-       if ($_xh[$parser]['lv']!=3) {\r
-               // "lookforvalue==3" means that we've found an entire value\r
-               // and should discard any further character data\r
-               if ($_xh[$parser]['lv']==1) {  \r
-                       // if we've found text and we're just in a <value> then\r
-                       // turn quoting on, as this will be a string\r
-                       $_xh[$parser]['qt']=1; \r
-                       // and say we've found a value\r
-                       $_xh[$parser]['lv']=2; \r
+\r
+       function xmlrpc_encode_entitites($data) \r
+       {\r
+               $length = strlen($data);\r
+               $escapeddata = "";\r
+               for($position = 0; $position < $length; $position++)\r
+               {\r
+                       $character = substr($data, $position, 1);\r
+                       $code = Ord($character);\r
+                       switch($code) {\r
+                               case 34:\r
+                               $character = "&quot;";\r
+                               break;\r
+                               case 38:\r
+                               $character = "&amp;";\r
+                               break;\r
+                               case 39:\r
+                               $character = "&apos;";\r
+                               break;\r
+                               case 60:\r
+                               $character = "&lt;";\r
+                               break;\r
+                               case 62:\r
+                               $character = "&gt;";\r
+                               break;\r
+                               default:\r
+                               if ($code < 32 || $code > 159)\r
+                                       $character = ("&#".strval($code).";");\r
+                               break;\r
+                       }\r
+                       $escapeddata .= $character;\r
                }\r
-       // replace characters that eval would\r
-       // do special things with\r
-       $_xh[$parser]['ac'].=str_replace('$', '\$',\r
-               str_replace('"', '\"', str_replace(chr(92),\r
-                       $xmlrpc_backslash, $data)));\r
+               return $escapeddata;\r
        }\r
-}\r
-\r
-function xmlrpc_dh($parser, $data)\r
-{\r
-  global $_xh;\r
-  if (substr($data, 0, 1) == "&" && substr($data, -1, 1) == ";") {\r
-               if ($_xh[$parser]['lv']==1) {  \r
-                       $_xh[$parser]['qt']=1; \r
-                       $_xh[$parser]['lv']=2; \r
+\r
+       function xmlrpc_se($parser, $name, $attrs)\r
+       {\r
+               global $_xh, $xmlrpcDateTime, $xmlrpcString;\r
+\r
+               switch($name)\r
+               {\r
+                       case 'STRUCT':\r
+                       case 'ARRAY':\r
+                               $_xh[$parser]['st'].='array(';\r
+                               $_xh[$parser]['cm']++;\r
+                               // this last line turns quoting off\r
+                               // this means if we get an empty array we'll\r
+                               // simply get a bit of whitespace in the eval\r
+                               $_xh[$parser]['qt']=0;\r
+                               break;\r
+                       case 'NAME':\r
+                               $_xh[$parser]['st'].='"';\r
+                               $_xh[$parser]['ac']='';\r
+                               break;\r
+                       case 'FAULT':\r
+                               $_xh[$parser]['isf']=1;\r
+                               break;\r
+                       case 'PARAM':\r
+                               $_xh[$parser]['st']='';\r
+                               break;\r
+                       case 'VALUE':\r
+                               $_xh[$parser]['st'].='new xmlrpcval(';\r
+                               $_xh[$parser]['vt']=$xmlrpcString;\r
+                               $_xh[$parser]['ac']='';\r
+                               $_xh[$parser]['qt']=0;\r
+                               $_xh[$parser]['lv']=1;\r
+                               // look for a value: if this is still 1 by the\r
+                               // time we reach the first data segment then the type is string\r
+                               // by implication and we need to add in a quote\r
+                               break;\r
+                       case 'I4':\r
+                       case 'INT':\r
+                       case 'STRING':\r
+                       case 'BOOLEAN':\r
+                       case 'DOUBLE':\r
+                       case 'DATETIME.ISO8601':\r
+                       case 'BASE64':\r
+                               $_xh[$parser]['ac']=''; // reset the accumulator\r
+\r
+                               if ($name=='DATETIME.ISO8601' || $name=='STRING')\r
+                               {\r
+                                       $_xh[$parser]['qt']=1;\r
+                                       if ($name=='DATETIME.ISO8601')\r
+                                       {\r
+                                               $_xh[$parser]['vt']=$xmlrpcDateTime;\r
+                                       }\r
+                               }\r
+                               elseif ($name=='BASE64')\r
+                               {\r
+                                       $_xh[$parser]['qt']=2;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // No quoting is required here -- but\r
+                                       // at the end of the element we must check\r
+                                       // for data format errors.\r
+                                       $_xh[$parser]['qt']=0;\r
+                               }\r
+                               break;\r
+                       case 'MEMBER':\r
+                               $_xh[$parser]['ac']='';\r
+                               break;\r
+                       default:\r
+                               break;\r
                }\r
-               $_xh[$parser]['ac'].=str_replace('$', '\$',\r
-                               str_replace('"', '\"', str_replace(chr(92),\r
-                                       $xmlrpc_backslash, $data)));\r
-  }\r
-}\r
-\r
-class xmlrpc_client {\r
-  var $path;\r
-  var $server;\r
-  var $port;\r
-  var $errno;\r
-  var $errstring;\r
-  var $debug=0;\r
-  var $username="";\r
-  var $password="";\r
-  var $cert="";\r
-  var $certpass="";\r
-  \r
-  function xmlrpc_client($path, $server, $port=0) {\r
-    $this->port=$port; $this->server=$server; $this->path=$path;\r
-  }\r
-\r
-  function setDebug($in) {\r
-               if ($in) { \r
-                       $this->debug=1;\r
-               } else {\r
-                       $this->debug=0;\r
+\r
+               if ($name!='VALUE')\r
+               {\r
+                       $_xh[$parser]['lv']=0;\r
                }\r
-  }\r
-\r
-  function setCredentials($u, $p) {\r
-    $this->username=$u;\r
-    $this->password=$p;\r
-  }\r
-\r
-  function setCertificate($cert, $certpass) {\r
-    $this->cert = $cert;\r
-    $this->certpass = $certpass;\r
-  }\r
-\r
-  function send($msg, $timeout=0, $method='http') {\r
-    // where msg is an xmlrpcmsg\r
-    $msg->debug=$this->debug;\r
\r
-    if ($method == 'https') {\r
-      return $this->sendPayloadHTTPS($msg,\r
-                                    $this->server,\r
-                                    $this->port, $timeout,\r
-                                    $this->username, $this->password,\r
-                                    $this->cert,\r
-                                    $this->certpass);\r
-    } else {\r
-      return $this->sendPayloadHTTP10($msg, $this->server, $this->port,\r
-                                     $timeout, $this->username, \r
-                                     $this->password);\r
-    }\r
-  }\r
-\r
-  function sendPayloadHTTP10($msg, $server, $port, $timeout=0,\r
-                            $username="", $password="") {\r
-    if ($port==0) $port=80;\r
-    if($timeout>0)\r
-      $fp=@fsockopen($server, $port,\r
-                   $this->errno, $this->errstr, $timeout);\r
-    else\r
-      $fp=@fsockopen($server, $port,\r
-                   $this->errno, $this->errstr);\r
-    if (!$fp) {   \r
-      return 0;\r
-    }\r
-    // Only create the payload if it was not created previously\r
-    if(empty($msg->payload)) $msg->createPayload();\r
-    \r
-    // thanks to Grant Rauscher <grant7@firstworld.net>\r
-    // for this\r
-    $credentials="";\r
-    if ($username!="") {\r
-      $credentials="Authorization: Basic " .\r
-       base64_encode($username . ":" . $password) . "\r\n";\r
-    }\r
-    \r
-    $op= "POST " . $this->path. " HTTP/1.0\r\nUser-Agent: PHP XMLRPC 1.0\r\n" .\r
-      "Host: ". $this->server  . "\r\n" .\r
-      $credentials . \r
-      "Content-Type: text/xml\r\nContent-Length: " .\r
-      strlen($msg->payload) . "\r\n\r\n" .\r
-      $msg->payload;\r
-    \r
-    if (!fputs($fp, $op, strlen($op))) {\r
-      $this->errstr="Write error";\r
-      return 0;\r
-    }\r
-    $resp=$msg->parseResponseFile($fp);\r
-    fclose($fp);\r
-    return $resp;\r
-  }\r
-\r
-  // contributed by Justin Miller <justin@voxel.net>\r
-  // requires curl to be built into PHP\r
-  function sendPayloadHTTPS($msg, $server, $port, $timeout=0,\r
-                           $username="", $password="", $cert="",\r
-                           $certpass="") {\r
-    global $xmlrpcerr, $xmlrpcstr;\r
-    if ($port == 0) $port = 443;\r
-    \r
-    // Only create the payload if it was not created previously\r
-    if(empty($msg->payload)) $msg->createPayload();\r
-    \r
-    if (!function_exists("curl_init")) {\r
-      $r=new xmlrpcresp(0, $xmlrpcerr["no_ssl"],\r
-                       $xmlrpcstr["no_ssl"]);\r
-      return $r;\r
-    }\r
-\r
-    $curl = curl_init("https://" . $server . ':' . $port .\r
-                     $this->path);\r
-    \r
-    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);\r
-    // results into variable\r
-    if ($this->debug) {\r
-      curl_setopt($curl, CURLOPT_VERBOSE, 1);\r
-    }\r
-    curl_setopt($curl, CURLOPT_USERAGENT, 'PHP XMLRPC 1.0');\r
-    // required for XMLRPC\r
-    curl_setopt($curl, CURLOPT_POST, 1);\r
-    // post the data\r
-    curl_setopt($curl, CURLOPT_POSTFIELDS, $msg->payload);\r
-    // the data\r
-    curl_setopt($curl, CURLOPT_HEADER, 1);\r
-    // return the header too\r
-    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));\r
-    // required for XMLRPC\r
-    if ($timeout) curl_setopt($curl, CURLOPT_TIMEOUT, $timeout == 1 ? 1 :\r
-                             $timeout - 1);\r
-    // timeout is borked\r
-    if ($username && $password) curl_setopt($curl, CURLOPT_USERPWD,\r
-                                           "$username:$password"); \r
-    // set auth stuff\r
-    if ($cert) curl_setopt($curl, CURLOPT_SSLCERT, $cert);\r
-    // set cert file\r
-    if ($certpass) curl_setopt($curl, CURLOPT_SSLCERTPASSWD,\r
-                      $certpass);                    \r
-    // set cert password\r
-    \r
-    $result = curl_exec($curl);\r
-    \r
-    if (!$result) {\r
-      $resp=new xmlrpcresp(0, \r
-                          $xmlrpcerr["curl_fail"],\r
-                          $xmlrpcstr["curl_fail"]. ": ". \r
-                          curl_error($curl));\r
-    } else {\r
-      $resp = $msg->parseResponse($result);\r
-    }\r
-    curl_close($curl);\r
-    return $resp;\r
-  }\r
-\r
-} // end class xmlrpc_client\r
-\r
-class xmlrpcresp {\r
-  var $xv;\r
-  var $fn;\r
-  var $fs;\r
-  var $hdrs;\r
-\r
-  function xmlrpcresp($val, $fcode=0, $fstr="") {\r
-    if ($fcode!=0) {\r
-      $this->xv=0;\r
-      $this->fn=$fcode;\r
-      $this->fs=htmlspecialchars($fstr);\r
-    } else {\r
-      $this->xv=$val;\r
-      $this->fn=0;\r
-    }\r
-  }\r
-\r
-  function faultCode() { \r
-               if (isset($this->fn)) \r
-                       return $this->fn;\r
-               else\r
-                       return 0; \r
        }\r
 \r
-  function faultString() { return $this->fs; }\r
-  function value() { return $this->xv; }\r
-\r
-  function serialize() { \r
-       $rs="<methodResponse>\n";\r
-       if ($this->fn) {\r
-         $rs.="<fault>\r
-  <value>\r
-    <struct>\r
-      <member>\r
-        <name>faultCode</name>\r
-        <value><int>" . $this->fn . "</int></value>\r
-      </member>\r
-      <member>\r
-        <name>faultString</name>\r
-        <value><string>" . $this->fs . "</string></value>\r
-      </member>\r
-    </struct>\r
-  </value>\r
-</fault>";\r
-       } else {\r
-         $rs.="<params>\n<param>\n" . $this->xv->serialize() . \r
-               "</param>\n</params>";\r
+       function xmlrpc_ee($parser, $name)\r
+       {\r
+               global $_xh,$xmlrpcTypes,$xmlrpcString;\r
+\r
+               switch($name)\r
+               {\r
+                       case 'STRUCT':\r
+                       case 'ARRAY':\r
+                               if ($_xh[$parser]['cm'] && substr($_xh[$parser]['st'], -1) ==',')\r
+                               {\r
+                                       $_xh[$parser]['st']=substr($_xh[$parser]['st'],0,-1);\r
+                               }\r
+                               $_xh[$parser]['st'].=')';\r
+                               $_xh[$parser]['vt']=strtolower($name);\r
+                               $_xh[$parser]['cm']--;\r
+                               break;\r
+                       case 'NAME':\r
+                               $_xh[$parser]['st'].= $_xh[$parser]['ac'] . '" => ';\r
+                               break;\r
+                       case 'BOOLEAN':\r
+                               // special case here: we translate boolean 1 or 0 into PHP\r
+                               // constants true or false\r
+                               // NB: this simple checks helps a lot sanitizing input, ie no\r
+                               // security problems around here\r
+                               if ($_xh[$parser]['ac']=='1')\r
+                               {\r
+                                       $_xh[$parser]['ac']='true';\r
+                               }\r
+                               else\r
+                               {\r
+                                       $_xh[$parser]['ac']='false';\r
+                               }\r
+                               $_xh[$parser]['vt']=strtolower($name);\r
+                               // Drop through intentionally.\r
+                       case 'I4':\r
+                       case 'INT':\r
+                       case 'STRING':\r
+                       case 'DOUBLE':\r
+                       case 'DATETIME.ISO8601':\r
+                       case 'BASE64':\r
+                               if ($_xh[$parser]['qt']==1)\r
+                               {\r
+                                       // we use double quotes rather than single so backslashification works OK\r
+                                       $_xh[$parser]['st'].='"'. $_xh[$parser]['ac'] . '"';\r
+                               }\r
+                               elseif ($_xh[$parser]['qt']==2)\r
+                               {\r
+                                       $_xh[$parser]['st'].='base64_decode("'. $_xh[$parser]['ac'] . '")';\r
+                               }\r
+                               elseif ($name=='BOOLEAN')\r
+                               {\r
+                                       $_xh[$parser]['st'].=$_xh[$parser]['ac'];\r
+                               }\r
+                               elseif ($name=='DOUBLE')\r
+                               {\r
+                                       // we have a DOUBLE\r
+                                       // we must check that only 0123456789-.<space> are characters here\r
+                                       if (!ereg("^[+-]?[eE0123456789 \\t\\.]+$", $_xh[$parser]['ac']))\r
+                                       {\r
+                                               // TODO: find a better way of throwing an error\r
+                                               // than this!\r
+                                               error_log('XML-RPC: non numeric value received in DOUBLE: '.$_xh[$parser]['ac']);\r
+                                               $_xh[$parser]['st'].="'ERROR_NON_NUMERIC_FOUND'";\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // it's ok, add it on\r
+                                               $_xh[$parser]['st'].=(double)$_xh[$parser]['ac'];\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       // we have an I4/INT\r
+                                       // we must check that only 0123456789-<space> are characters here\r
+                                       if (!ereg("^[+-]?[0123456789 \\t]+$", $_xh[$parser]['ac']))\r
+                                       {\r
+                                               // TODO: find a better way of throwing an error\r
+                                               // than this!\r
+                                               error_log('XML-RPC: non numeric value received in INT: '.$_xh[$parser]['ac']);\r
+                                               $_xh[$parser]['st'].="'ERROR_NON_NUMERIC_FOUND'";\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // it's ok, add it on\r
+                                               $_xh[$parser]['st'].=(int)$_xh[$parser]['ac'];\r
+                                       }\r
+                               }\r
+                               $_xh[$parser]['ac']='';\r
+                               $_xh[$parser]['qt']=0;\r
+                               $_xh[$parser]['lv']=3; // indicate we've found a value\r
+                               break;\r
+                       case 'VALUE':\r
+                               // deal with a string value\r
+                               if (strlen($_xh[$parser]['ac'])>0 &&\r
+                                       $_xh[$parser]['vt']==$xmlrpcString)\r
+                               {\r
+                                       $_xh[$parser]['st'].='"'. $_xh[$parser]['ac'] . '"';\r
+                               }\r
+                               // This if() detects if no scalar was inside <VALUE></VALUE>\r
+                               // and pads an empty ''.\r
+                               if($_xh[$parser]['st'][strlen($_xh[$parser]['st'])-1] == '(')\r
+                               {\r
+                                       $_xh[$parser]['st'].= '""';\r
+                               }\r
+                               // G. Giunta 2005/03/12 save some chars in the reconstruction of string vals...\r
+                               if ($_xh[$parser]['vt'] != $xmlrpcString)\r
+                                       $_xh[$parser]['st'].=", '" . $_xh[$parser]['vt'] . "')";\r
+                               else\r
+                                       $_xh[$parser]['st'].=")";\r
+                               if ($_xh[$parser]['cm'])\r
+                               {\r
+                                       $_xh[$parser]['st'].=',';\r
+                               }\r
+                               break;\r
+                       case 'MEMBER':\r
+                               $_xh[$parser]['ac']='';\r
+                               $_xh[$parser]['qt']=0;\r
+                               break;\r
+                       case 'DATA':\r
+                               $_xh[$parser]['ac']='';\r
+                               $_xh[$parser]['qt']=0;\r
+                               break;\r
+                       case 'PARAM':\r
+                               $_xh[$parser]['params'][]=$_xh[$parser]['st'];\r
+                               break;\r
+                       case 'METHODNAME':\r
+                               $_xh[$parser]['method']=ereg_replace("^[\n\r\t ]+", '', $_xh[$parser]['ac']);\r
+                               break;\r
+                       // BOOLEAN HAS BEEN ENUMERATED ABOVE!\r
+                       /*case 'BOOLEAN':\r
+                               // special case here: we translate boolean 1 or 0 into PHP\r
+                               // constants true or false\r
+                               if ($_xh[$parser]['ac']=='1')\r
+                               {\r
+                                       $_xh[$parser]['ac']='true';\r
+                               }\r
+                               else\r
+                               {\r
+                                       $_xh[$parser]['ac']='false';\r
+                                       $_xh[$parser]['vt']=strtolower($name);\r
+                               }\r
+                               break;*/\r
+                       default:\r
+                               break;\r
+               }\r
+               // if it's a valid type name, set the type\r
+               if (isset($xmlrpcTypes[strtolower($name)]))\r
+               {\r
+                       $_xh[$parser]['vt']=strtolower($name);\r
+               }\r
        }\r
-       $rs.="\n</methodResponse>";\r
-       return $rs;\r
-  }\r
-}\r
-\r
-class xmlrpcmsg {\r
-  var $payload;\r
-  var $methodname;\r
-  var $params=array();\r
-  var $debug=0;\r
-\r
-  function xmlrpcmsg($meth, $pars=0) {\r
-               $this->methodname=$meth;\r
-               if (is_array($pars) && sizeof($pars)>0) {\r
-                       for($i=0; $i<sizeof($pars); $i++) \r
-                               $this->addParam($pars[$i]);\r
+\r
+       function xmlrpc_cd($parser, $data)\r
+       {\r
+               global $_xh, $xmlrpc_backslash;\r
+\r
+               //if (ereg("^[\n\r \t]+$", $data)) return;\r
+               // print "adding [${data}]\n";\r
+\r
+               if ($_xh[$parser]['lv']!=3)\r
+               {\r
+                       // "lookforvalue==3" means that we've found an entire value\r
+                       // and should discard any further character data\r
+                       if ($_xh[$parser]['lv']==1)\r
+                       {\r
+                               // if we've found text and we're just in a <value> then\r
+                               // turn quoting on, as this will be a string\r
+                               $_xh[$parser]['qt']=1;\r
+                               // and say we've found a value\r
+                               $_xh[$parser]['lv']=2;\r
+                       }\r
+                       if(!@isset($_xh[$parser]['ac']))\r
+                       {\r
+                               $_xh[$parser]['ac'] = '';\r
+                       }\r
+                       $_xh[$parser]['ac'].=str_replace('$', '\$', str_replace('"', '\"', str_replace(chr(92),$xmlrpc_backslash, $data)));\r
                }\r
-  }\r
-\r
-  function xml_header() {\r
-       return "<" . "?xml version=\"1.0\"?".">\n<methodCall>\n";\r
-  }\r
-\r
-  function xml_footer() {\r
-       return "</methodCall>\n";\r
-  }\r
-\r
-  function createPayload() {\r
-       $this->payload=$this->xml_header();\r
-       $this->payload.="<methodName>" . $this->methodname . "</methodName>\n";\r
-       //      if (sizeof($this->params)) {\r
-         $this->payload.="<params>\n";\r
-         for($i=0; $i<sizeof($this->params); $i++) {\r
-               $p=$this->params[$i];\r
-               $this->payload.="<param>\n" . $p->serialize() .\r
-                 "</param>\n";\r
-         }\r
-         $this->payload.="</params>\n";\r
-       // }\r
-       $this->payload.=$this->xml_footer();\r
-       $this->payload=str_replace("\n", "\r\n", $this->payload);\r
-  }\r
-\r
-  function method($meth="") {\r
-       if ($meth!="") {\r
-         $this->methodname=$meth;\r
        }\r
-       return $this->methodname;\r
-  }\r
 \r
-  function serialize() {\r
-               $this->createPayload();\r
-               return $this->payload;\r
-  }\r
+       function xmlrpc_dh($parser, $data)\r
+       {\r
+               global $_xh, $xmlrpc_backslash;\r
+               if (substr($data, 0, 1) == '&' && substr($data, -1, 1) == ';')\r
+               {\r
+                       if ($_xh[$parser]['lv']==1)\r
+                       {\r
+                               $_xh[$parser]['qt']=1;\r
+                               $_xh[$parser]['lv']=2;\r
+                       }\r
+                       $_xh[$parser]['ac'].=str_replace('$', '\$', str_replace('"', '\"', str_replace(chr(92),$xmlrpc_backslash, $data)));\r
+               }\r
+       }\r
 \r
-  function addParam($par) { $this->params[]=$par; }\r
-  function getParam($i) { return $this->params[$i]; }\r
-  function getNumParams() { return sizeof($this->params); }\r
+       class xmlrpc_client\r
+       {\r
+               var $path;\r
+               var $server;\r
+               var $port;\r
+               var $errno;\r
+               var $errstr;\r
+               var $debug=0;\r
+               var $username='';\r
+               var $password='';\r
+               var $cert='';\r
+               var $certpass='';\r
+               var $verifypeer=1;\r
+               var $verifyhost=1;\r
+               var $no_multicall=false;\r
+\r
+               function xmlrpc_client($path, $server, $port=0)\r
+               {\r
+                       $this->port=$port; $this->server=$server; $this->path=$path;\r
+               }\r
 \r
-  function parseResponseFile($fp) {\r
-       $ipd="";\r
+               function setDebug($in)\r
+               {\r
+                       if ($in)\r
+                       {\r
+                               $this->debug=1;\r
+                       }\r
+                       else\r
+                       {\r
+                               $this->debug=0;\r
+                       }\r
+               }\r
 \r
-       while($data=fread($fp, 32768)) {\r
-         $ipd.=$data;\r
-       }\r
-       return $this->parseResponse($ipd);\r
-  }\r
-\r
-  function parseResponse($data="") {\r
-       global $_xh,$xmlrpcerr,$xmlrpcstr;\r
-       global $xmlrpc_defencoding;\r
-\r
-       \r
-       $parser = xml_parser_create($xmlrpc_defencoding);\r
-\r
-       $_xh[$parser]=array();\r
-\r
-       $_xh[$parser]['st']=""; \r
-       $_xh[$parser]['cm']=0; \r
-       $_xh[$parser]['isf']=0; \r
-       $_xh[$parser]['ac']="";\r
-       $_xh[$parser]['qt']="";\r
-       $_xh[$parser]['ha']="";\r
-       $_xh[$parser]['ac']="";\r
-\r
-       xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);\r
-       xml_set_element_handler($parser, "xmlrpc_se", "xmlrpc_ee");\r
-       xml_set_character_data_handler($parser, "xmlrpc_cd");\r
-       xml_set_default_handler($parser, "xmlrpc_dh");\r
-       $xmlrpc_value=new xmlrpcval;\r
-\r
-       if ($this->debug)\r
-         print "<PRE>---GOT---\n" . htmlspecialchars($data) . \r
-               "\n---END---\n</PRE>";\r
-       if ($data=="") {\r
-         error_log("No response received from server.");\r
-         $r=new xmlrpcresp(0, $xmlrpcerr["no_data"],\r
-                           $xmlrpcstr["no_data"]);\r
-         xml_parser_free($parser);\r
-         return $r;\r
-       }\r
-       // see if we got an HTTP 200 OK, else bomb\r
-       // but only do this if we're using the HTTP protocol.\r
-       if (ereg("^HTTP",$data) && \r
-                       !ereg("^HTTP/[0-9\.]+ 200 ", $data)) {\r
-               $errstr= substr($data, 0, strpos($data, "\n")-1);\r
-               error_log("HTTP error, got response: " .$errstr);\r
-               $r=new xmlrpcresp(0, $xmlrpcerr["http_error"],\r
-                                 $xmlrpcstr["http_error"]. " (" . $errstr . ")");\r
-               xml_parser_free($parser);\r
-               return $r;\r
-       }\r
+               function setCredentials($u, $p)\r
+               {\r
+                       $this->username=$u;\r
+                       $this->password=$p;\r
+               }\r
 \r
-       // if using HTTP, then gotta get rid of HTTP headers here\r
-       // and we store them in the 'ha' bit of our data array\r
-       if (ereg("^HTTP", $data)) {\r
-               $ar=explode("\r\n", $data);\r
-               $newdata="";\r
-               $hdrfnd=0;\r
-               for ($i=0; $i<sizeof($ar); $i++) {\r
-                       if (!$hdrfnd) {\r
-                               if (strlen($ar[$i])>0) {\r
-                                       $_xh[$parser]['ha'].=$ar[$i]. "\r\n";\r
-                               } else {\r
-                                       $hdrfnd=1; \r
-                               }\r
-                       } else {\r
-                               $newdata.=$ar[$i] . "\r\n";\r
+               function setCertificate($cert, $certpass)\r
+               {\r
+                       $this->cert = $cert;\r
+                       $this->certpass = $certpass;\r
+               }\r
+\r
+               function setSSLVerifyPeer($i)\r
+               {\r
+                       $this->verifypeer = $i;\r
+               }\r
+\r
+               function setSSLVerifyHost($i)\r
+               {\r
+                       $this->verifyhost = $i;\r
+               }\r
+\r
+               function send($msg, $timeout=0, $method='http')\r
+               {\r
+                       if (is_array($msg))\r
+                       {\r
+                               // $msg is an array of xmlrpcmsg's\r
+                               return $this->multicall($msg, $timeout, $method);\r
+                       }\r
+\r
+                       // where msg is an xmlrpcmsg\r
+                       $msg->debug=$this->debug;\r
+\r
+                       if ($method == 'https')\r
+                       {\r
+                               return $this->sendPayloadHTTPS($msg,\r
+                               $this->server,\r
+                               $this->port, $timeout,\r
+                               $this->username, $this->password,\r
+                               $this->cert,\r
+                               $this->certpass);\r
+                       }\r
+                       else\r
+                       {\r
+                               return $this->sendPayloadHTTP10($msg, $this->server, $this->port,\r
+                               $timeout, $this->username, \r
+                               $this->password);\r
                        }\r
                }\r
-               $data=$newdata;\r
-       }\r
-       \r
-       if (!xml_parse($parser, $data, sizeof($data))) {\r
-               // thanks to Peter Kocks <peter.kocks@baygate.com>\r
-               if((xml_get_current_line_number($parser)) == 1)   \r
-                       $errstr = "XML error at line 1, check URL";\r
-               else\r
-                       $errstr = sprintf("XML error: %s at line %d",\r
-                                                                                               xml_error_string(xml_get_error_code($parser)),\r
-                                                                                               xml_get_current_line_number($parser));\r
-               error_log($errstr);\r
-               $r=new xmlrpcresp(0, $xmlrpcerr["invalid_return"],\r
-                                                                                       $xmlrpcstr["invalid_return"]);\r
-               xml_parser_free($parser);\r
-               return $r;\r
-       }\r
-       xml_parser_free($parser);\r
-       if ($this->debug) {\r
-         print "<PRE>---EVALING---[" . \r
-               strlen($_xh[$parser]['st']) . " chars]---\n" . \r
-               htmlspecialchars($_xh[$parser]['st']) . ";\n---END---</PRE>";\r
-       }\r
-       if (strlen($_xh[$parser]['st'])==0) {\r
-         // then something odd has happened\r
-         // and it's time to generate a client side error\r
-         // indicating something odd went on\r
-         $r=new xmlrpcresp(0, $xmlrpcerr["invalid_return"],\r
-                                               $xmlrpcstr["invalid_return"]);\r
-       } else {\r
-         eval('$v=' . $_xh[$parser]['st'] . '; $allOK=1;');\r
-         if ($_xh[$parser]['isf']) {\r
-               $f=$v->structmem("faultCode");\r
-               $fs=$v->structmem("faultString");\r
-               $r=new xmlrpcresp($v, $f->scalarval(), \r
-                                                 $fs->scalarval());\r
-         } else {\r
-               $r=new xmlrpcresp($v);\r
-         }\r
-       }\r
-       $r->hdrs=split("\r?\n", $_xh[$parser]['ha']);\r
-       return $r;\r
-  }\r
 \r
-}\r
+               function sendPayloadHTTP10($msg, $server, $port, $timeout=0,$username='', $password='')\r
+               {\r
+                       global $xmlrpcerr, $xmlrpcstr, $xmlrpcName, $xmlrpcVersion, $xmlrpc_defencoding;\r
+                       if ($port==0)\r
+                       {\r
+                               $port=80;\r
+                       }\r
+                       if($timeout>0)\r
+                       {\r
+                               $fp=@fsockopen($server, $port,$this->errno, $this->errstr, $timeout);\r
+                       }\r
+                       else\r
+                       {\r
+                               $fp=@fsockopen($server, $port,$this->errno, $this->errstr);\r
+                       }\r
+                       if ($fp)\r
+                       {\r
+                               if ($timeout>0 && function_exists('stream_set_timeout'))\r
+                                       stream_set_timeout($fp, $timeout);\r
+                       }\r
+                       else\r
+                       {\r
+                               $this->errstr='Connect error';\r
+                               $r=new xmlrpcresp(0, $xmlrpcerr['http_error'],$xmlrpcstr['http_error']);\r
+                               return $r;\r
+                       }\r
+                       // Only create the payload if it was not created previously\r
+                       if(empty($msg->payload))\r
+                       {\r
+                               $msg->createPayload();\r
+                       }\r
 \r
-class xmlrpcval {\r
-  var $me=array();\r
-  var $mytype=0;\r
+                       // thanks to Grant Rauscher <grant7@firstworld.net>\r
+                       // for this\r
+                       $credentials='';\r
+                       if ($username!='')\r
+                       {\r
+                               $credentials='Authorization: Basic ' . base64_encode($username . ':' . $password) . "\r\n";\r
+                       }\r
 \r
-  function xmlrpcval($val=-1, $type="") {\r
-               global $xmlrpcTypes;\r
-               $this->me=array();\r
-               $this->mytype=0;\r
-               if ($val!=-1 || $type!="") {\r
-                       if ($type=="") $type="string";\r
-                       if ($xmlrpcTypes[$type]==1) {\r
-                               $this->addScalar($val,$type);\r
-                       }\r
-         else if ($xmlrpcTypes[$type]==2)\r
-                       $this->addArray($val);\r
-                       else if ($xmlrpcTypes[$type]==3)\r
-                               $this->addStruct($val);\r
+                       $op= "POST " . $this->path. " HTTP/1.0\r\n" .\r
+                               "User-Agent: " . $xmlrpcName . " " . $xmlrpcVersion . "\r\n" .\r
+                               "Host: ". $server . "\r\n" .\r
+                               $credentials . \r
+                               "Accept-Charset: " . $xmlrpc_defencoding . "\r\n" .\r
+                               "Content-Type: text/xml\r\nContent-Length: " .\r
+                               strlen($msg->payload) . "\r\n\r\n" .\r
+                               $msg->payload;\r
+\r
+                       if (!fputs($fp, $op, strlen($op)))\r
+                       {\r
+                               $this->errstr='Write error';\r
+                               $r=new xmlrpcresp(0, $xmlrpcerr['http_error'], $xmlrpcstr['http_error']);\r
+                               return $r;\r
+                       }\r
+                       $resp=$msg->parseResponseFile($fp);\r
+                       fclose($fp);\r
+                       return $resp;\r
                }\r
-  }\r
 \r
-  function addScalar($val, $type="string") {\r
-               global $xmlrpcTypes, $xmlrpcBoolean;\r
+               // contributed by Justin Miller <justin@voxel.net>\r
+               // requires curl to be built into PHP\r
+               function sendPayloadHTTPS($msg, $server, $port, $timeout=0,$username='', $password='', $cert='',$certpass='')\r
+               {\r
+                       global $xmlrpcerr, $xmlrpcstr, $xmlrpcVersion, $xmlrpc_internalencoding;\r
+                       if ($port == 0)\r
+                       {\r
+                               $port = 443;\r
+                       }\r
 \r
-               if ($this->mytype==1) {\r
-                       echo "<B>xmlrpcval</B>: scalar can have only one value<BR>";\r
-                       return 0;\r
+                       // Only create the payload if it was not created previously\r
+                       if(empty($msg->payload))\r
+                       {\r
+                               $msg->createPayload();\r
+                       }\r
+\r
+                       if (!function_exists('curl_init'))\r
+                       {\r
+                               $this->errstr='SSL unavailable on this install';\r
+                               $r=new xmlrpcresp(0, $xmlrpcerr['no_ssl'], $xmlrpcstr['no_ssl']);\r
+                               return $r;\r
+                       }\r
+\r
+                       $curl = curl_init('https://' . $server . ':' . $port . $this->path);\r
+\r
+                       curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);\r
+                       // results into variable\r
+                       if ($this->debug)\r
+                       {\r
+                               curl_setopt($curl, CURLOPT_VERBOSE, 1);\r
+                       }\r
+                       curl_setopt($curl, CURLOPT_USERAGENT, 'PHP XMLRPC '.$xmlrpcVersion);\r
+                       // required for XMLRPC\r
+                       curl_setopt($curl, CURLOPT_POST, 1);\r
+                       // post the data\r
+                       curl_setopt($curl, CURLOPT_POSTFIELDS, $msg->payload);\r
+                       // the data\r
+                       curl_setopt($curl, CURLOPT_HEADER, 1);\r
+                       // return the header too\r
+                       curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/xml', 'Accept-Charset: '.$xmlrpc_internalencoding));\r
+                       // whether to verify remote host's cert\r
+                       curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifypeer);\r
+                       // 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\r
+                       curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost);\r
+                       // required for XMLRPC\r
+                       if ($timeout)\r
+                       {\r
+                               curl_setopt($curl, CURLOPT_TIMEOUT, $timeout == 1 ? 1 : $timeout - 1);\r
+                       }\r
+                       // timeout is borked\r
+                       if ($username && $password)\r
+                       {\r
+                               curl_setopt($curl, CURLOPT_USERPWD,"$username:$password");\r
+                       }\r
+                       // set auth stuff\r
+                       if ($cert)\r
+                       {\r
+                               curl_setopt($curl, CURLOPT_SSLCERT, $cert);\r
+                       }\r
+                       // set cert file\r
+                       if ($certpass)\r
+                       {\r
+                               curl_setopt($curl, CURLOPT_SSLCERTPASSWD,$certpass);\r
+                       }\r
+                       // set cert password\r
+\r
+                       $result = curl_exec($curl);\r
+\r
+                       if (!$result)\r
+                       {\r
+                               $this->errstr='no response';\r
+                               $resp=new xmlrpcresp(0, $xmlrpcerr['curl_fail'], $xmlrpcstr['curl_fail']. ': '. curl_error($curl));\r
+                               curl_close($curl);\r
+                       }\r
+                       else\r
+                       {\r
+                               curl_close($curl);\r
+                               $resp = $msg->parseResponse($result);\r
+                       }\r
+                       return $resp;\r
                }\r
-               $typeof=$xmlrpcTypes[$type];\r
-               if ($typeof!=1) {\r
-                       echo "<B>xmlrpcval</B>: not a scalar type (${typeof})<BR>";\r
-                       return 0;\r
+\r
+               function multicall($msgs, $timeout=0, $method='http')\r
+               {\r
+                       $results = false;\r
+\r
+                       if (! $this->no_multicall)\r
+                       {\r
+                               $results = $this->_try_multicall($msgs, $timeout, $method);\r
+                               /* TODO - this is not php3-friendly */\r
+                               // if($results !== false)\r
+                               if(is_array($results))\r
+                               {\r
+                                       // Either the system.multicall succeeded, or the send\r
+                                       // failed (e.g. due to HTTP timeout). In either case,\r
+                                       // we're done for now.\r
+                                       return $results;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // system.multicall unsupported by server,\r
+                                       // don't try it next time...\r
+                                       $this->no_multicall = true;\r
+                               }\r
+                       }\r
+\r
+                       // system.multicall is unupported by server:\r
+                       //   Emulate multicall via multiple requests\r
+                       $results = array();\r
+                       //foreach($msgs as $msg)\r
+                       @reset($msgs);\r
+                       while(list(,$msg) = @each($msgs))\r
+                       {\r
+                               $results[] = $this->send($msg, $timeout, $method);\r
+                       }\r
+                       return $results;\r
                }\r
-               \r
-               if ($type==$xmlrpcBoolean) {\r
-                       if (strcasecmp($val,"true")==0 || \r
-                                       $val==1 || ($val==true &&\r
-                                                                                       strcasecmp($val,"false"))) {\r
-                               $val=1;\r
-                       } else {\r
-                               $val=0;\r
+\r
+               // Attempt to boxcar $msgs via system.multicall.\r
+               function _try_multicall($msgs, $timeout, $method)\r
+               {\r
+                       // Construct multicall message\r
+                       $calls = array();\r
+                       //foreach($msgs as $msg)\r
+                       @reset($msgs);\r
+                       while(list(,$msg) = @each($msgs))\r
+                       {\r
+                               $call['methodName'] = new xmlrpcval($msg->method(),'string');\r
+                               $numParams = $msg->getNumParams();\r
+                               $params = array();\r
+                               for ($i = 0; $i < $numParams; $i++)\r
+                               {\r
+                                       $params[$i] = $msg->getParam($i);\r
+                               }\r
+                               $call['params'] = new xmlrpcval($params, 'array');\r
+                               $calls[] = new xmlrpcval($call, 'struct');\r
+                       }\r
+                       $multicall = new xmlrpcmsg('system.multicall');\r
+                       $multicall->addParam(new xmlrpcval($calls, 'array'));\r
+\r
+                       // Attempt RPC call\r
+                       $result = $this->send($multicall, $timeout, $method);\r
+                       if(!is_object($result))\r
+                       {\r
+                               return ($result || 0); // transport failed\r
+                       }\r
+\r
+                       if($result->faultCode() != 0)\r
+                       {\r
+                               return false;           // system.multicall failed\r
                        }\r
+\r
+                       // Unpack responses.\r
+                       $rets = $result->value();\r
+                       if($rets->kindOf() != 'array')\r
+                       {\r
+                               return false;           // bad return type from system.multicall\r
+                       }\r
+                       $numRets = $rets->arraysize();\r
+                       if($numRets != count($msgs))\r
+                       {\r
+                               return false;           // wrong number of return values.\r
+                       }\r
+\r
+                       $response = array();\r
+                       for ($i = 0; $i < $numRets; $i++)\r
+                       {\r
+                               $val = $rets->arraymem($i);\r
+                               switch ($val->kindOf())\r
+                               {\r
+                               case 'array':\r
+                                       if($val->arraysize() != 1)\r
+                                       {\r
+                                               return false;           // Bad value\r
+                                       }\r
+                                       // Normal return value\r
+                                       $response[$i] = new xmlrpcresp($val->arraymem(0));\r
+                                       break;\r
+                               case 'struct':\r
+                                       $code = $val->structmem('faultCode');\r
+                                       if($code->kindOf() != 'scalar' || $code->scalartyp() != 'int')\r
+                                       {\r
+                                               return false;\r
+                                       }\r
+                                       $str = $val->structmem('faultString');\r
+                                       if($str->kindOf() != 'scalar' || $str->scalartyp() != 'string')\r
+                                       {\r
+                                               return false;\r
+                                       }\r
+                                       $response[$i] = new xmlrpcresp(0, $code->scalarval(), $str->scalarval());\r
+                                       break;\r
+                               default:\r
+                                       return false;\r
+                               }\r
+                       }\r
+                       return $response;\r
                }\r
-               \r
-               if ($this->mytype==2) {\r
-                       // we're adding to an array here\r
-                       $ar=$this->me["array"];\r
-                       $ar[]=new xmlrpcval($val, $type);\r
-                       $this->me["array"]=$ar;\r
-               } else {\r
-                       // a scalar, so set the value and remember we're scalar\r
-                       $this->me[$type]=$val;\r
-                       $this->mytype=$typeof;\r
+       } // end class xmlrpc_client\r
+\r
+       class xmlrpcresp\r
+       {\r
+               var $val = 0;\r
+               var $errno = 0;\r
+               var $errstr = '';\r
+               var $hdrs = array();\r
+\r
+               function xmlrpcresp($val, $fcode = 0, $fstr = '')\r
+               {\r
+                       if ($fcode != 0)\r
+                       {\r
+                               // error\r
+                               $this->errno = $fcode;\r
+                               $this->errstr = $fstr;\r
+                               //$this->errstr = htmlspecialchars($fstr); // XXX: encoding probably shouldn't be done here; fix later.\r
+                       }\r
+                       elseif (!is_object($val))\r
+                       {\r
+                               // programmer error\r
+                               error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to xmlrpcresp. Defaulting to empty value.");\r
+                               $this->val = new xmlrpcval();\r
+                       }\r
+                       else\r
+                       {\r
+                               // success\r
+                               $this->val = $val;\r
+                       }\r
                }\r
-               return 1;\r
-  }\r
 \r
-  function addArray($vals) {\r
-               global $xmlrpcTypes;\r
-               if ($this->mytype!=0) {\r
-                       echo "<B>xmlrpcval</B>: already initialized as a [" . \r
-                               $this->kindOf() . "]<BR>";\r
-                       return 0;\r
+               function faultCode()\r
+               {\r
+                       return $this->errno;\r
                }\r
 \r
-               $this->mytype=$xmlrpcTypes["array"];\r
-               $this->me["array"]=$vals;\r
-               return 1;\r
-  }\r
-\r
-  function addStruct($vals) {\r
-       global $xmlrpcTypes;\r
-       if ($this->mytype!=0) {\r
-         echo "<B>xmlrpcval</B>: already initialized as a [" . \r
-               $this->kindOf() . "]<BR>";\r
-         return 0;\r
-       }\r
-       $this->mytype=$xmlrpcTypes["struct"];\r
-       $this->me["struct"]=$vals;\r
-       return 1;\r
-  }\r
-\r
-  function dump($ar) {\r
-       reset($ar);\r
-       while ( list( $key, $val ) = each( $ar ) ) {\r
-         echo "$key => $val<br>";\r
-         if ($key == 'array')\r
-               while ( list( $key2, $val2 ) = each( $val ) ) {\r
-                 echo "-- $key2 => $val2<br>";\r
+               function faultString()\r
+               {\r
+                       return $this->errstr;\r
+               }\r
+\r
+               function value()\r
+               {\r
+                       return $this->val;\r
+               }\r
+\r
+               function serialize()\r
+               {\r
+                       global $xmlrpc_defencoding;\r
+                       $result = "<methodResponse>\n";\r
+                       if ($this->errno)\r
+                       {\r
+                               // G. Giunta 2005/2/13: let non-ASCII response messages be tolerated by clients\r
+                               $result .= '<fault>\r
+<value>\r
+<struct>\r
+<member>\r
+<name>faultCode</name>\r
+<value><int>' . $this->errno . '</int></value>\r
+</member>\r
+<member>\r
+<name>faultString</name>\r
+<value><string>' . mb_convert_encoding(xmlrpc_encode_entitites($this->errstr), $xmlrpc_defencoding, _CHARSET) . '</string></value>\r
+</member>\r
+</struct>\r
+</value>\r
+</fault>';\r
+                       }\r
+                       else\r
+                       {\r
+                               $result .= "<params>\n<param>\n" .\r
+                                       $this->val->serialize() . \r
+                                       "</param>\n</params>";\r
+                       }\r
+                       $result .= "\n</methodResponse>";\r
+                       return $result;\r
                }\r
        }\r
-  }\r
-\r
-  function kindOf() {\r
-       switch($this->mytype) {\r
-       case 3:\r
-         return "struct";\r
-         break;\r
-       case 2:\r
-         return "array";\r
-         break;\r
-       case 1:\r
-         return "scalar";\r
-         break;\r
-       default:\r
-         return "undef";\r
+\r
+       class xmlrpcmsg\r
+       {\r
+               var $payload;\r
+               var $methodname;\r
+               var $params=array();\r
+               var $debug=0;\r
+\r
+               function xmlrpcmsg($meth, $pars=0)\r
+               {\r
+                       $this->methodname=$meth;\r
+                       if (is_array($pars) && sizeof($pars)>0)\r
+                       {\r
+                               for($i=0; $i<sizeof($pars); $i++)\r
+                               {\r
+                                       $this->addParam($pars[$i]);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               function xml_header()\r
+               {\r
+                       return "<?xml version=\"1.0\"?" . ">\n<methodCall>\n";\r
+               }\r
+\r
+               function xml_footer()\r
+               {\r
+                       return "</methodCall>\n";\r
+               }\r
+\r
+               function createPayload()\r
+               {\r
+                       $this->payload=$this->xml_header();\r
+                       $this->payload.='<methodName>' . $this->methodname . "</methodName>\n";\r
+                       //      if (sizeof($this->params)) {\r
+                       $this->payload.="<params>\n";\r
+                       for($i=0; $i<sizeof($this->params); $i++)\r
+                       {\r
+                               $p=$this->params[$i];\r
+                               $this->payload.="<param>\n" . $p->serialize() .\r
+                               "</param>\n";\r
+                       }\r
+                       $this->payload.="</params>\n";\r
+                       // }\r
+                       $this->payload.=$this->xml_footer();\r
+                       //$this->payload=str_replace("\n", "\r\n", $this->payload);\r
+               }\r
+\r
+               function method($meth='')\r
+               {\r
+                       if ($meth!='')\r
+                       {\r
+                               $this->methodname=$meth;\r
+                       }\r
+                       return $this->methodname;\r
+               }\r
+\r
+               function serialize()\r
+               {\r
+                       $this->createPayload();\r
+                       return $this->payload;\r
+               }\r
+\r
+               function addParam($par) { $this->params[]=$par; }\r
+               function getParam($i) { return $this->params[$i]; }\r
+               function getNumParams() { return sizeof($this->params); }\r
+\r
+               function parseResponseFile($fp)\r
+               {\r
+                       $ipd='';\r
+                       while($data=fread($fp, 32768))\r
+                       {\r
+                               $ipd.=$data;\r
+                       }\r
+                       return $this->parseResponse($ipd);\r
+               }\r
+\r
+               function parseResponse($data='')\r
+               {\r
+                       global $_xh,$xmlrpcerr,$xmlrpcstr;\r
+                       global $xmlrpc_defencoding, $xmlrpc_internalencoding;\r
+\r
+                       $hdrfnd = 0;\r
+                       if($this->debug)\r
+                       {\r
+                               //by maHo, replaced htmlspecialchars with htmlentities\r
+                               print "<PRE>---GOT---\n" . htmlentities($data) . "\n---END---\n</PRE>";\r
+                       }\r
+\r
+                       if($data == '')\r
+                       {\r
+                               error_log('No response received from server.');\r
+                               $r = new xmlrpcresp(0, $xmlrpcerr['no_data'], $xmlrpcstr['no_data']);\r
+                               return $r;\r
+                       }\r
+                       // see if we got an HTTP 200 OK, else bomb\r
+                       // but only do this if we're using the HTTP protocol.\r
+                       if(ereg("^HTTP",$data))\r
+                       {\r
+                               // Strip HTTP 1.1 100 Continue header if present\r
+                               while (ereg('^HTTP/1.1 1[0-9]{2}', $data))\r
+                               {\r
+                                       $pos = strpos($data, 'HTTP', 12);\r
+                                       // server sent a Continue header without any (valid) content following...\r
+                                       // give the client a chance to know it\r
+                                       if (!$pos && !is_int($pos)) // works fine in php 3, 4 and 5\r
+                                               break;\r
+                                       $data = substr($data, $pos);\r
+                               }\r
+                               if (!ereg("^HTTP/[0-9\\.]+ 200 ", $data))\r
+                               {\r
+                                       $errstr= substr($data, 0, strpos($data, "\n")-1);\r
+                                       error_log('HTTP error, got response: ' .$errstr);\r
+                                       $r=new xmlrpcresp(0, $xmlrpcerr['http_error'], $xmlrpcstr['http_error']. ' (' . $errstr . ')');\r
+                                       return $r;\r
+                               }\r
+                       }\r
+                       $parser = xml_parser_create($xmlrpc_defencoding);\r
+\r
+                       // G. Giunta 2004/04/06\r
+                       // Clean up the accumulator, or it will grow indefinitely long\r
+                       // if making xmlrpc calls for a while\r
+                       $_xh=array();\r
+                       $_xh[$parser]=array();\r
+                       $_xh[$parser]['headers'] = array();\r
+\r
+                       // separate HTTP headers from data\r
+                       if (ereg("^HTTP", $data))\r
+                       {\r
+                               // be tolerant to usage of \n instead of \r\n to separate headers and data\r
+                               // (even though it is not valid http)\r
+                               $pos = strpos($data,"\r\n\r\n");\r
+                               if($pos || is_int($pos))\r
+                                       $bd = $pos+4;\r
+                               else\r
+                               {\r
+                                       $pos = strpos($data,"\n\n");\r
+                                       if($pos || is_int($pos))\r
+                                               $bd = $pos+2;\r
+                                       else\r
+                                       {\r
+                                               // No separation between response headers and body: fault?\r
+                                               $bd = 0;\r
+                                       }\r
+                               }\r
+                               // be tolerant to line endings, and extra empty lines\r
+                               $ar = split("\r?\n", trim(substr($data, 0, $pos)));\r
+                               while (list(,$line) = @each($ar))\r
+                               {\r
+                                       // take care of multi-line headers\r
+                                       $arr = explode(':',$line);\r
+                                       if(count($arr) > 1)\r
+                                       {\r
+                                               $header_name = trim($arr[0]);\r
+                                               // TO DO: some headers (the ones that allow a CSV list of values)\r
+                                               // do allow many values to be passed using multiple header lines.\r
+                                               // We should add content to $_xh[$parser]['headers'][$header_name]\r
+                                               // instead of replacing it for those...\r
+                                               $_xh[$parser]['headers'][$header_name] = $arr[1];\r
+                                               for ($i = 2; $i < count($arr); $i++)\r
+                                               {\r
+                                                       $_xh[$parser]['headers'][$header_name] .= ':'.$arr[$i];\r
+                                               } // while\r
+                                               $_xh[$parser]['headers'][$header_name] = trim($_xh[$parser]['headers'][$header_name]);\r
+                                       } else if (isset($header_name))\r
+                                       {\r
+                                               $_xh[$parser]['headers'][$header_name] .= ' ' . trim($line);\r
+                                       }\r
+                               }\r
+                               $data = substr($data, $bd);\r
+\r
+                               if ($this->debug && count($_xh[$parser]['headers']))\r
+                               {\r
+                                       print '<PRE>';\r
+                                       //foreach ($_xh[$parser]['headers'] as $header)\r
+                                       @reset($_xh[$parser]['headers']);\r
+                                       while(list($header, $value) = @each($_xh[$parser]['headers']))\r
+                                       {\r
+                                               print "HEADER: $header: $value\n";\r
+                                       }\r
+                                       print "</PRE>\n";\r
+                               }\r
+                       }\r
+\r
+                       // be tolerant of extra whitespace in response body\r
+                       $data = trim($data);\r
+\r
+                       // be tolerant of junk after methodResponse (e.g. javascript automatically inserted by free hosts)\r
+                       // idea from Luca Mariano <luca.mariano@email.it> originally in PEARified version of the lib\r
+                       $bd = false;\r
+                       $pos = strpos($data, "</methodResponse>");\r
+                       while ($pos || is_int($pos))\r
+                       {\r
+                               $bd = $pos+17;\r
+                               $pos = strpos($data, "</methodResponse>", $bd);\r
+                       }\r
+                       if ($bd)\r
+                               $data = substr($data, 0, $bd);\r
+\r
+                       $_xh[$parser]['st']='';\r
+                       $_xh[$parser]['cm']=0;\r
+                       $_xh[$parser]['isf']=0;\r
+                       $_xh[$parser]['ac']='';\r
+                       $_xh[$parser]['qt']='';\r
+\r
+                       xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);\r
+                       // G. Giunta 2005/02/13: PHP internally uses ISO-8859-1, so we have to tell\r
+                       // the xml parser to give us back data in the expected charset\r
+                       xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $xmlrpc_internalencoding);\r
+\r
+                       xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee');\r
+                       xml_set_character_data_handler($parser, 'xmlrpc_cd');\r
+                       xml_set_default_handler($parser, 'xmlrpc_dh');\r
+                       //$xmlrpc_value=new xmlrpcval;\r
+\r
+                       if (!xml_parse($parser, $data, sizeof($data)))\r
+                       {\r
+                               // thanks to Peter Kocks <peter.kocks@baygate.com>\r
+                               if((xml_get_current_line_number($parser)) == 1)\r
+                               {\r
+                                       $errstr = 'XML error at line 1, check URL';\r
+                               }\r
+                               else\r
+                               {\r
+                                       $errstr = sprintf('XML error: %s at line %d',\r
+                                               xml_error_string(xml_get_error_code($parser)),\r
+                                               xml_get_current_line_number($parser));\r
+                               }\r
+                               error_log($errstr);\r
+                               $r=new xmlrpcresp(0, $xmlrpcerr['invalid_return'], $xmlrpcstr['invalid_return'].' ('.$errstr.')');\r
+                               xml_parser_free($parser);\r
+                               if ($this->debug)\r
+                                       echo $errstr;\r
+                               $r->hdrs = $_xh[$parser]['headers'];\r
+                               return $r;\r
+                       }\r
+                       xml_parser_free($parser);\r
+                       if ($this->debug)\r
+                       {\r
+                               print "<PRE>---EVALING---[" .\r
+                               strlen($_xh[$parser]['st']) . " chars]---\n" .\r
+                               htmlspecialchars($_xh[$parser]['st']) . ";\n---END---</PRE>";\r
+                       }\r
+                       if (strlen($_xh[$parser]['st'])==0)\r
+                       {\r
+                               // then something odd has happened\r
+                               // and it's time to generate a client side error\r
+                               // indicating something odd went on\r
+                               $r=new xmlrpcresp(0, $xmlrpcerr['invalid_return'],\r
+                               $xmlrpcstr['invalid_return']);\r
+                       }\r
+                       else\r
+                       {\r
+                               $allOK=0;\r
+                               @eval('$v=' . $_xh[$parser]['st'] . '; $allOK=1;');\r
+                               if (!$allOK)\r
+                               {\r
+                                       $r = new xmlrpcresp(0, $xmlrpcerr['invalid_return'], $xmlrpcstr['invalid_return']);\r
+                               }\r
+                               else\r
+                               if ($_xh[$parser]['isf'])\r
+                               {\r
+                                       $errno_v = $v->structmem('faultCode');\r
+                                       $errstr_v = $v->structmem('faultString');\r
+                                       $errno = $errno_v->scalarval();\r
+\r
+                                       if ($errno == 0)\r
+                                       {\r
+                                               // FAULT returned, errno needs to reflect that\r
+                                               $errno = -1;\r
+                                       }\r
+\r
+                                       $r = new xmlrpcresp($v, $errno, $errstr_v->scalarval());\r
+                               }\r
+                               else\r
+                               {\r
+                                       $r=new xmlrpcresp($v);\r
+                               }\r
+                       }\r
+\r
+                       $r->hdrs = $_xh[$parser]['headers'];\r
+                       return $r;\r
+               }\r
        }\r
-  }\r
-\r
-  function serializedata($typ, $val) {\r
-               $rs="";\r
-               global $xmlrpcTypes, $xmlrpcBase64, $xmlrpcString,\r
-                       $xmlrpcBoolean;\r
-               switch($xmlrpcTypes[$typ]) {\r
-               case 3:\r
-                       // struct\r
-                       $rs.="<struct>\n";\r
-                       reset($val);\r
-                       while(list($key2, $val2)=each($val)) {\r
-                               $rs.="<member><name>${key2}</name>\n";\r
-                               $rs.=$this->serializeval($val2);\r
-                               $rs.="</member>\n";\r
-                       }\r
-                       $rs.="</struct>";\r
-                       break;\r
-               case 2:\r
-                       // array\r
-                       $rs.="<array>\n<data>\n";\r
-                       for($i=0; $i<sizeof($val); $i++) {\r
-                               $rs.=$this->serializeval($val[$i]);\r
-                       }\r
-                       $rs.="</data>\n</array>";\r
-                       break;\r
-               case 1:\r
-                       switch ($typ) {\r
-                       case $xmlrpcBase64:\r
-                               $rs.="<${typ}>" . base64_encode($val) . "</${typ}>";\r
-                               break;\r
-                       case $xmlrpcBoolean:\r
-                               $rs.="<${typ}>" . ($val ? "1" : "0") . "</${typ}>";\r
+\r
+       class xmlrpcval\r
+       {\r
+               var $me=array();\r
+               var $mytype=0;\r
+\r
+               function xmlrpcval($val=-1, $type='')\r
+               {\r
+                       global $xmlrpcTypes;\r
+                       $this->me=array();\r
+                       $this->mytype=0;\r
+                       if ($val!=-1 || !is_int($val) || $type!='')\r
+                       {\r
+                               if ($type=='')\r
+                               {\r
+                                       $type='string';\r
+                               }\r
+                               if ($xmlrpcTypes[$type]==1)\r
+                               {\r
+                                       $this->addScalar($val,$type);\r
+                               }\r
+                               elseif ($xmlrpcTypes[$type]==2)\r
+                               {\r
+                                       $this->addArray($val);\r
+                               }\r
+                               elseif ($xmlrpcTypes[$type]==3)\r
+                               {\r
+                                       $this->addStruct($val);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               function addScalar($val, $type='string')\r
+               {\r
+                       global $xmlrpcTypes, $xmlrpcBoolean, $xmlrpc_defencoding;\r
+\r
+                       if ($this->mytype==1)\r
+                       {\r
+                               echo '<B>xmlrpcval</B>: scalar can have only one value<BR>';\r
+                               return 0;\r
+                       }\r
+                       $typeof=$xmlrpcTypes[$type];\r
+                       if ($typeof!=1)\r
+                       {\r
+                               echo '<B>xmlrpcval</B>: not a scalar type (${typeof})<BR>';\r
+                               return 0;\r
+                       }\r
+\r
+                       if ($type==$xmlrpcBoolean)\r
+                       {\r
+                               if (strcasecmp($val,'true')==0 || $val==1 || ($val==true && strcasecmp($val,'false')))\r
+                               {\r
+                                       $val=1;\r
+                               }\r
+                               else\r
+                               {\r
+                                       $val=0;\r
+                               }\r
+                       }\r
+\r
+                       if ($this->mytype==2)\r
+                       {\r
+                               // we're adding to an array here\r
+                               $ar=$this->me['array'];\r
+                               $ar[]=new xmlrpcval($val, $type);\r
+                               $this->me['array']=$ar;\r
+                       }\r
+                       else\r
+                       {\r
+                               // a scalar, so set the value and remember we're scalar\r
+                               $this->me[$type]=$val;\r
+                               $this->mytype=$typeof;\r
+                       }\r
+                       return 1;\r
+               }\r
+\r
+               function addArray($vals)\r
+               {\r
+                       global $xmlrpcTypes;\r
+                       if ($this->mytype!=0)\r
+                       {\r
+                               echo '<B>xmlrpcval</B>: already initialized as a [' . $this->kindOf() . ']<BR>';\r
+                               return 0;\r
+                       }\r
+\r
+                       $this->mytype=$xmlrpcTypes['array'];\r
+                       $this->me['array']=$vals;\r
+                       return 1;\r
+               }\r
+\r
+               function addStruct($vals)\r
+               {\r
+                       global $xmlrpcTypes;\r
+                       if ($this->mytype!=0)\r
+                       {\r
+                               echo '<B>xmlrpcval</B>: already initialized as a [' . $this->kindOf() . ']<BR>';\r
+                               return 0;\r
+                       }\r
+                       $this->mytype=$xmlrpcTypes['struct'];\r
+                       $this->me['struct']=$vals;\r
+                       return 1;\r
+               }\r
+\r
+               function dump($ar)\r
+               {\r
+                       reset($ar);\r
+                       while ( list( $key, $val ) = each( $ar ) )\r
+                       {\r
+                               echo "$key => $val<br>";\r
+                               if ($key == 'array')\r
+                               {\r
+                                       while ( list( $key2, $val2 ) = each( $val ) )\r
+                                       {\r
+                                               echo "-- $key2 => $val2<br>";\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+               function kindOf()\r
+               {\r
+                       switch($this->mytype)\r
+                       {\r
+                               case 3:\r
+                                       return 'struct';\r
                                        break;\r
-                       case $xmlrpcString:\r
-                               $rs.="<${typ}>" . htmlspecialchars($val). "</${typ}>";\r
-                               break;\r
-                       default:\r
-                               $rs.="<${typ}>${val}</${typ}>";\r
+                               case 2:\r
+                                       return 'array';\r
+                                       break;\r
+                               case 1:\r
+                                       return 'scalar';\r
+                                       break;\r
+                               default:\r
+                                       return 'undef';\r
                        }\r
-                       break;\r
-               default:\r
-                       break;\r
                }\r
-               return $rs;\r
-  }\r
 \r
-  function serialize() {\r
-       return $this->serializeval($this);\r
-  }\r
+               function serializedata($typ, $val)\r
+               {\r
+                       $rs='';\r
+                       global $xmlrpcTypes, $xmlrpcBase64, $xmlrpcString,\r
+                       $xmlrpcBoolean, $xmlrpc_defencoding;\r
+                       switch(@$xmlrpcTypes[$typ])\r
+                       {\r
+                               case 3:\r
+                                       // struct\r
+                                       $rs.="<struct>\n";\r
+                                       reset($val);\r
+                                       while(list($key2, $val2)=each($val))\r
+                                       {\r
+                                               $rs.="<member><name>${key2}</name>\n";\r
+                                               $rs.=$this->serializeval($val2);\r
+                                               $rs.="</member>\n";\r
+                                       }\r
+                                       $rs.='</struct>';\r
+                                       break;\r
+                               case 2:\r
+                                       // array\r
+                                       $rs.="<array>\n<data>\n";\r
+                                       for($i=0; $i<sizeof($val); $i++)\r
+                                       {\r
+                                               $rs.=$this->serializeval($val[$i]);\r
+                                       }\r
+                                       $rs.="</data>\n</array>";\r
+                                       break;\r
+                               case 1:\r
+                                       switch ($typ)\r
+                                       {\r
+                                               case $xmlrpcBase64:\r
+                                                       $rs.="<${typ}>" . base64_encode($val) . "</${typ}>";\r
+                                                       break;\r
+                                               case $xmlrpcBoolean:\r
+                                                       $rs.="<${typ}>" . ($val ? '1' : '0') . "</${typ}>";\r
+                                                       break;\r
+                                               case $xmlrpcString:\r
+                                                       // G. Giunta 2005/2/13: do NOT use htmlentities, since\r
+                                                       // it will produce named html entities, which are invalid xml\r
+                                                       // $rs.="<${typ}>" . xmlrpc_encode_entitites($val). "</${typ}>";\r
+                                                       // $rs.="<${typ}>" . htmlentities($val). "</${typ}>";\r
+                                                       \r
+                                                       // N. Leenheer 2005/6/30: Use CDATA instead... \r
+                                                       $rs.="<${typ}><![CDATA[" . mb_convert_encoding($val, $xmlrpc_defencoding, _CHARSET). "]]></${typ}>";\r
+                                                       break;\r
+                                               default:\r
+                                                       $rs.="<${typ}>${val}</${typ}>";\r
+                                       }\r
+                                       break;\r
+                               default:\r
+                                       break;\r
+                       }\r
+                       return $rs;\r
+               }\r
 \r
-  function serializeval($o) {\r
-               global $xmlrpcTypes;\r
-               $rs="";\r
-               $ar=$o->me;\r
-               reset($ar);\r
-               list($typ, $val) = each($ar);\r
-               $rs.="<value>";\r
-               $rs.=$this->serializedata($typ, $val);\r
-               $rs.="</value>\n";\r
-               return $rs;\r
-  }\r
-\r
-  function structmem($m) {\r
-               $nv=$this->me["struct"][$m];\r
-               return $nv;\r
-  }\r
-\r
-       function structreset() {\r
-               reset($this->me["struct"]);\r
-       }\r
-       \r
-       function structeach() {\r
-               return each($this->me["struct"]);\r
-       }\r
+               function serialize()\r
+               {\r
+                       return $this->serializeval($this);\r
+               }\r
+\r
+               function serializeval($o)\r
+               {\r
+                       //global $xmlrpcTypes;\r
+                       $rs='';\r
+                       $ar=$o->me;\r
+                       reset($ar);\r
+                       list($typ, $val) = each($ar);\r
+                       $rs.='<value>';\r
+                       $rs.=$this->serializedata($typ, $val);\r
+                       $rs.="</value>\n";\r
+                       return $rs;\r
+               }\r
+\r
+               function structmem($m)\r
+               {\r
+                       $nv=$this->me['struct'][$m];\r
+                       return $nv;\r
+               }\r
+\r
+               function structreset()\r
+               {\r
+                       reset($this->me['struct']);\r
+               }\r
 \r
-  function getval() {\r
-               // UNSTABLE\r
-               global $xmlrpcBoolean, $xmlrpcBase64;\r
-               reset($this->me);\r
-               list($a,$b)=each($this->me);\r
-               // contributed by I Sofer, 2001-03-24\r
-               // add support for nested arrays to scalarval\r
-               // i've created a new method here, so as to\r
-               // preserve back compatibility\r
+               function structeach()\r
+               {\r
+                       return each($this->me['struct']);\r
+               }\r
 \r
-               if (is_array($b))    {\r
-                       foreach ($b as $id => $cont) {\r
-                               $b[$id] = $cont->scalarval();\r
+               function getval()\r
+               {\r
+                       // UNSTABLE\r
+                       global $xmlrpcBoolean, $xmlrpcBase64;\r
+                       reset($this->me);\r
+                       list($a,$b)=each($this->me);\r
+                       // contributed by I Sofer, 2001-03-24\r
+                       // add support for nested arrays to scalarval\r
+                       // i've created a new method here, so as to\r
+                       // preserve back compatibility\r
+\r
+                       if (is_array($b))\r
+                       {\r
+                               @reset($b);\r
+                               while(list($id,$cont) = @each($b))\r
+                               {\r
+                                       $b[$id] = $cont->scalarval();\r
+                               }\r
+                       }\r
+\r
+                       // add support for structures directly encoding php objects\r
+                       if (is_object($b))\r
+                       {\r
+                               $t = get_object_vars($b);\r
+                               @reset($t);\r
+                               while(list($id,$cont) = @each($t))\r
+                               {\r
+                                       $t[$id] = $cont->scalarval();\r
+                               }\r
+                               @reset($t);\r
+                               while(list($id,$cont) = @each($t))\r
+                               {\r
+                                       eval('$b->'.$id.' = $cont;');\r
+                               }\r
                        }\r
+                       // end contrib\r
+                       return $b;\r
+               }\r
+\r
+               function scalarval()\r
+               {\r
+                       //global $xmlrpcBoolean, $xmlrpcBase64;\r
+                       reset($this->me);\r
+                       list($a,$b)=each($this->me);\r
+                       return $b;\r
                }\r
 \r
-               // add support for structures directly encoding php objects\r
-               if (is_object($b))  {\r
-                       $t = get_object_vars($b);\r
-                       foreach ($t as $id => $cont) {\r
-                               $t[$id] = $cont->scalarval();\r
+               function scalartyp()\r
+               {\r
+                       global $xmlrpcI4, $xmlrpcInt;\r
+                       reset($this->me);\r
+                       list($a,$b)=each($this->me);\r
+                       if ($a==$xmlrpcI4)\r
+                       {\r
+                               $a=$xmlrpcInt;\r
                        }\r
-                       foreach ($t as $id => $cont) {\r
-                               eval('$b->'.$id.' = $cont;');\r
+                       return $a;\r
+               }\r
+\r
+               function arraymem($m)\r
+               {\r
+                       $nv=$this->me['array'][$m];\r
+                       return $nv;\r
+               }\r
+\r
+               function arraysize()\r
+               {\r
+                       reset($this->me);\r
+                       list($a,$b)=each($this->me);\r
+                       return sizeof($b);\r
+               }\r
+       }\r
+\r
+       // date helpers\r
+       function iso8601_encode($timet, $utc=0)\r
+       {\r
+               // return an ISO8601 encoded string\r
+               // really, timezones ought to be supported\r
+               // but the XML-RPC spec says:\r
+               //\r
+               // "Don't assume a timezone. It should be specified by the server in its\r
+               // documentation what assumptions it makes about timezones."\r
+               // \r
+               // these routines always assume localtime unless \r
+               // $utc is set to 1, in which case UTC is assumed\r
+               // and an adjustment for locale is made when encoding\r
+               if (!$utc)\r
+               {\r
+                       $t=strftime("%Y%m%dT%H:%M:%S", $timet);\r
+               }\r
+               else\r
+               {\r
+                       if (function_exists('gmstrftime'))\r
+                       {\r
+                               // gmstrftime doesn't exist in some versions\r
+                               // of PHP\r
+                               $t=gmstrftime("%Y%m%dT%H:%M:%S", $timet);\r
+                       }\r
+                       else\r
+                       {\r
+                               $t=strftime("%Y%m%dT%H:%M:%S", $timet-date('Z'));\r
                        }\r
                }\r
-               // end contrib\r
-               return $b;\r
-  }\r
-\r
-  function scalarval() {\r
-               global $xmlrpcBoolean, $xmlrpcBase64;\r
-               reset($this->me);\r
-               list($a,$b)=each($this->me);\r
-               return $b;\r
-  }\r
-\r
-  function scalartyp() {\r
-               global $xmlrpcI4, $xmlrpcInt;\r
-               reset($this->me);\r
-               list($a,$b)=each($this->me);\r
-               if ($a==$xmlrpcI4) \r
-                       $a=$xmlrpcInt;\r
-               return $a;\r
-  }\r
-\r
-  function arraymem($m) {\r
-               $nv=$this->me["array"][$m];\r
-               return $nv;\r
-  }\r
-\r
-  function arraysize() {\r
-               reset($this->me);\r
-               list($a,$b)=each($this->me);\r
-               return sizeof($b);\r
-  }\r
-}\r
-\r
-// date helpers\r
-function iso8601_encode($timet, $utc=0) {\r
-       // return an ISO8601 encoded string\r
-       // really, timezones ought to be supported\r
-       // but the XML-RPC spec says:\r
-       //\r
-       // "Don't assume a timezone. It should be specified by the server in its\r
-  // documentation what assumptions it makes about timezones."\r
-       // \r
-       // these routines always assume localtime unless \r
-       // $utc is set to 1, in which case UTC is assumed\r
-       // and an adjustment for locale is made when encoding\r
-       if (!$utc) {\r
-               $t=strftime("%Y%m%dT%H:%M:%S", $timet);\r
-       } else {\r
-               if (function_exists("gmstrftime")) \r
-                       // gmstrftime doesn't exist in some versions\r
-                       // of PHP\r
-                       $t=gmstrftime("%Y%m%dT%H:%M:%S", $timet);\r
-               else {\r
-                       $t=strftime("%Y%m%dT%H:%M:%S", $timet-date("Z"));\r
+               return $t;\r
+       }\r
+\r
+       function iso8601_decode($idate, $utc=0)\r
+       {\r
+               // return a timet in the localtime, or UTC\r
+               $t=0;\r
+               if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})", $idate, $regs))\r
+               {\r
+                       if ($utc)\r
+                       {\r
+                               $t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);\r
+                       }\r
+                       else\r
+                       {\r
+                               $t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);\r
+                       }\r
+               } \r
+               return $t;\r
+       }\r
+\r
+       /****************************************************************\r
+       * xmlrpc_decode takes a message in PHP xmlrpc object format and *\r
+       * tranlates it into native PHP types.                           *\r
+       *                                                               *\r
+       * author: Dan Libby (dan@libby.com)                             *\r
+       ****************************************************************/\r
+       function php_xmlrpc_decode($xmlrpc_val)\r
+       {\r
+               $kind = $xmlrpc_val->kindOf();\r
+\r
+               if($kind == 'scalar')\r
+               {\r
+                       return $xmlrpc_val->scalarval();\r
+               }\r
+               elseif($kind == 'array')\r
+               {\r
+                       $size = $xmlrpc_val->arraysize();\r
+                       $arr = array();\r
+\r
+                       for($i = 0; $i < $size; $i++)\r
+                       {\r
+                               $arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i));\r
+                       }\r
+                       return $arr;\r
+               }\r
+               elseif($kind == 'struct')\r
+               {\r
+                       $xmlrpc_val->structreset();\r
+                       $arr = array();\r
+\r
+                       while(list($key,$value)=$xmlrpc_val->structeach())\r
+                       {\r
+                               $arr[$key] = php_xmlrpc_decode($value);\r
+                       }\r
+                       return $arr;\r
                }\r
        }\r
-       return $t;\r
-}\r
-\r
-function iso8601_decode($idate, $utc=0) {\r
-       // return a timet in the localtime, or UTC\r
-       $t=0;\r
-       if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})",\r
-                                        $idate, $regs)) {\r
-               if ($utc) {\r
-                       $t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);\r
-               } else {\r
-                       $t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);\r
+\r
+       if(function_exists('xmlrpc_decode'))\r
+       {\r
+               define('XMLRPC_EPI_ENABLED','1');\r
+       }\r
+       else\r
+       {\r
+               define('XMLRPC_EPI_ENABLED','0');\r
+               function xmlrpc_decode($xmlrpc_val)\r
+               {\r
+                       $kind = $xmlrpc_val->kindOf();\r
+\r
+                       if($kind == 'scalar')\r
+                       {\r
+                               return $xmlrpc_val->scalarval();\r
+                       }\r
+                       elseif($kind == 'array')\r
+                       {\r
+                               $size = $xmlrpc_val->arraysize();\r
+                               $arr = array();\r
+\r
+                               for($i = 0; $i < $size; $i++)\r
+                               {\r
+                                       $arr[]=xmlrpc_decode($xmlrpc_val->arraymem($i));\r
+                               }\r
+                               return $arr;\r
+                       }\r
+                       elseif($kind == 'struct')\r
+                       {\r
+                               $xmlrpc_val->structreset();\r
+                               $arr = array();\r
+\r
+                               while(list($key,$value)=$xmlrpc_val->structeach())\r
+                               {\r
+                                       $arr[$key] = xmlrpc_decode($value);\r
+                               }\r
+                               return $arr;\r
+                       }\r
                }\r
-       } \r
-       return $t;\r
-}\r
-\r
-/****************************************************************\r
-* xmlrpc_decode takes a message in PHP xmlrpc object format and *\r
-* tranlates it into native PHP types.                           *\r
-*                                                               *\r
-* author: Dan Libby (dan@libby.com)                             *\r
-****************************************************************/\r
-function _xmlrpc_decode($xmlrpc_val) {\r
-   $kind = $xmlrpc_val->kindOf();\r
-\r
-   if($kind == "scalar") {\r
-      return $xmlrpc_val->scalarval();\r
-   }\r
-   else if($kind == "array") {\r
-      $size = $xmlrpc_val->arraysize();\r
-      $arr = array();\r
-\r
-      for($i = 0; $i < $size; $i++) {\r
-         $arr[]=_xmlrpc_decode($xmlrpc_val->arraymem($i));\r
-      }\r
-      return $arr; \r
-   }\r
-   else if($kind == "struct") {\r
-      $xmlrpc_val->structreset();\r
-      $arr = array();\r
-\r
-      while(list($key,$value)=$xmlrpc_val->structeach()) {\r
-         $arr[$key] = _xmlrpc_decode($value);\r
-      }\r
-      return $arr;\r
-   }\r
-}\r
-\r
-/****************************************************************\r
-* xmlrpc_encode takes native php types and encodes them into    *\r
-* xmlrpc PHP object format.                                     *\r
-* BUG: All sequential arrays are turned into structs.  I don't  *\r
-* know of a good way to determine if an array is sequential     *\r
-* only.                                                         *\r
-*                                                               *\r
-* feature creep -- could support more types via optional type   *\r
-* argument.                                                     *\r
-*                                                               *\r
-* author: Dan Libby (dan@libby.com)                             *\r
-****************************************************************/\r
-function _xmlrpc_encode($php_val) {\r
-   global $xmlrpcInt;\r
-   global $xmlrpcDouble;\r
-   global $xmlrpcString;\r
-   global $xmlrpcArray;\r
-   global $xmlrpcStruct;\r
-   global $xmlrpcBoolean;\r
-\r
-   $type = gettype($php_val);\r
-   $xmlrpc_val = new xmlrpcval;\r
-\r
-   switch($type) {\r
-      case "array":\r
-      case "object":\r
-         $arr = array();\r
-         while (list($k,$v) = each($php_val)) {\r
-            $arr[$k] = _xmlrpc_encode($v);\r
-         }\r
-         $xmlrpc_val->addStruct($arr);\r
-         break;\r
-      case "integer":\r
-         $xmlrpc_val->addScalar($php_val, $xmlrpcInt);\r
-         break;\r
-      case "double":\r
-         $xmlrpc_val->addScalar($php_val, $xmlrpcDouble);\r
-         break;\r
-      case "string":\r
-         $xmlrpc_val->addScalar($php_val, $xmlrpcString);\r
-         break;\r
-// <G_Giunta_2001-02-29>\r
-// Add support for encoding/decoding of booleans, since they are supported in PHP\r
-      case "boolean":\r
-         $xmlrpc_val->addScalar($php_val, $xmlrpcBoolean);\r
-         break;\r
-// </G_Giunta_2001-02-29>\r
-      case "unknown type":\r
-      default:\r
-       // giancarlo pinerolo <ping@alt.it>\r
-       // it has to return \r
-        // an empty object in case (which is already\r
-       // at this point), not a boolean. \r
-       break;\r
-   }\r
-   return $xmlrpc_val;\r
-}\r
+       }\r
 \r
+       /****************************************************************\r
+       * xmlrpc_encode takes native php types and encodes them into    *\r
+       * xmlrpc PHP object format.                                     *\r
+       * BUG: All sequential arrays are turned into structs.  I don't  *\r
+       * know of a good way to determine if an array is sequential     *\r
+       * only.                                                         *\r
+       *                                                               *\r
+       * feature creep -- could support more types via optional type   *\r
+       * argument.                                                     *\r
+       *                                                               *\r
+       * author: Dan Libby (dan@libby.com)                             *\r
+       ****************************************************************/\r
+       function php_xmlrpc_encode($php_val)\r
+       {\r
+               global $xmlrpcInt;\r
+               global $xmlrpcDouble;\r
+               global $xmlrpcString;\r
+               global $xmlrpcArray;\r
+               global $xmlrpcStruct;\r
+               global $xmlrpcBoolean;\r
+\r
+               $type = gettype($php_val);\r
+               $xmlrpc_val = new xmlrpcval;\r
+\r
+               switch($type)\r
+               {\r
+                       case 'array':\r
+                       case 'object':\r
+                               $arr = array();\r
+                               while (list($k,$v) = each($php_val))\r
+                               {\r
+                                       $arr[$k] = php_xmlrpc_encode($v);\r
+                               }\r
+                               $xmlrpc_val->addStruct($arr);\r
+                               break;\r
+                       case 'integer':\r
+                               $xmlrpc_val->addScalar($php_val, $xmlrpcInt);\r
+                               break;\r
+                       case 'double':\r
+                               $xmlrpc_val->addScalar($php_val, $xmlrpcDouble);\r
+                               break;\r
+                       case 'string':\r
+                               $xmlrpc_val->addScalar($php_val, $xmlrpcString);\r
+                               break;\r
+                               // <G_Giunta_2001-02-29>\r
+                               // Add support for encoding/decoding of booleans, since they are supported in PHP\r
+                       case 'boolean':\r
+                               $xmlrpc_val->addScalar($php_val, $xmlrpcBoolean);\r
+                               break;\r
+                               // </G_Giunta_2001-02-29>\r
+                       // catch "resource", "NULL", "user function", "unknown type"\r
+                       //case 'unknown type':\r
+                       default:\r
+                               // giancarlo pinerolo <ping@alt.it>\r
+                               // it has to return \r
+                               // an empty object in case (which is already\r
+                               // at this point), not a boolean. \r
+                               break;\r
+                       }\r
+                       return $xmlrpc_val;\r
+       }\r
+\r
+       if(XMLRPC_EPI_ENABLED == '0')\r
+       {\r
+               function xmlrpc_encode($php_val)\r
+               {\r
+                       global $xmlrpcInt;\r
+                       global $xmlrpcDouble;\r
+                       global $xmlrpcString;\r
+                       global $xmlrpcArray;\r
+                       global $xmlrpcStruct;\r
+                       global $xmlrpcBoolean;\r
+\r
+                       $type = gettype($php_val);\r
+                       $xmlrpc_val = new xmlrpcval;\r
+\r
+                       switch($type)\r
+                       {\r
+                               case 'array':\r
+                               case 'object':\r
+                                       $arr = array();\r
+                                       while (list($k,$v) = each($php_val))\r
+                                       {\r
+                                               $arr[$k] = xmlrpc_encode($v);\r
+                                       }\r
+                                       $xmlrpc_val->addStruct($arr);\r
+                                       break;\r
+                               case 'integer':\r
+                                       $xmlrpc_val->addScalar($php_val, $xmlrpcInt);\r
+                                       break;\r
+                               case 'double':\r
+                                       $xmlrpc_val->addScalar($php_val, $xmlrpcDouble);\r
+                                       break;\r
+                               case 'string':\r
+                                       $xmlrpc_val->addScalar($php_val, $xmlrpcString);\r
+                                       break;\r
+                                       // <G_Giunta_2001-02-29>\r
+                                       // Add support for encoding/decoding of booleans, since they are supported in PHP\r
+                               case 'boolean':\r
+                                       $xmlrpc_val->addScalar($php_val, $xmlrpcBoolean);\r
+                                       break;\r
+                                       // </G_Giunta_2001-02-29>\r
+                               //case 'unknown type':\r
+                               default:\r
+                                       // giancarlo pinerolo <ping@alt.it>\r
+                                       // it has to return \r
+                                       // an empty object in case (which is already\r
+                                       // at this point), not a boolean. \r
+                                       break;\r
+                       }\r
+                       return $xmlrpc_val;\r
+               }\r
+       }\r
 ?>\r
index db41065..a0aea22 100755 (executable)
@@ -1,10 +1,10 @@
 <?php\r
-// by Edd Dumbill (C) 1999-2001\r
+// by Edd Dumbill (C) 1999-2002\r
 // <edd@usefulinc.com>\r
-// $Id: xmlrpcs.inc.php,v 1.4 2005-03-16 08:10:35 kimitake Exp $\r
-// $NucleusJP: xmlrpcs.inc.php,v 1.5 2005/03/12 06:19:05 kimitake Exp $\r
+// $Id: xmlrpcs.inc.php,v 1.5 2005-08-13 07:20:34 kimitake Exp $\r
+// $NucleusJP: xmlrpcs.inc.php,v 1.4.2.1 2005/06/30 21:23:01 kimitake Exp $\r
 \r
-// Copyright (c) 1999,2000,2001 Edd Dumbill.\r
+// Copyright (c) 1999,2000,2002 Edd Dumbill.\r
 // All rights reserved.\r
 //\r
 // Redistribution and use in source and binary forms, with or without\r
 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
 // OF THE POSSIBILITY OF SUCH DAMAGE.\r
 \r
-// XML RPC Server class\r
-// requires: xmlrpc.inc\r
-\r
-// listMethods: either a string, or nothing\r
-$_xmlrpcs_listMethods_sig=array(array($xmlrpcArray, $xmlrpcString), \r
-                                                                                                                               array($xmlrpcArray));\r
-$_xmlrpcs_listMethods_doc='This method lists all the methods that the XML-RPC server knows how to dispatch';\r
-function _xmlrpcs_listMethods($server, $m) {\r
-       global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;\r
-       $v=new xmlrpcval();\r
-       $dmap=$server->dmap;\r
-       $outAr=array();\r
-       for(reset($dmap); list($key, $val)=each($dmap); ) {\r
-               $outAr[]=new xmlrpcval($key, "string");\r
-       }\r
-       $dmap=$_xmlrpcs_dmap;\r
-       for(reset($dmap); list($key, $val)=each($dmap); ) {\r
-               $outAr[]=new xmlrpcval($key, "string");\r
-       }\r
-       $v->addArray($outAr);\r
-       return new xmlrpcresp($v);\r
-}\r
-\r
-$_xmlrpcs_methodSignature_sig=array(array($xmlrpcArray, $xmlrpcString));\r
-$_xmlrpcs_methodSignature_doc='Returns an array of known signatures (an array of arrays) for the method name passed. If no signatures are known, returns a none-array (test for type != array to detect missing signature)';\r
-function _xmlrpcs_methodSignature($server, $m) {\r
-       global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;\r
-\r
-       $methName=$m->getParam(0);\r
-       $methName=$methName->scalarval();\r
-       if (ereg("^system\.", $methName)) {\r
-               $dmap=$_xmlrpcs_dmap; $sysCall=1;\r
-       } else {\r
-               $dmap=$server->dmap; $sysCall=0;\r
+       // XML RPC Server class\r
+       // requires: xmlrpc.inc\r
+\r
+       // listMethods: either a string, or nothing\r
+       $_xmlrpcs_listMethods_sig=array(array($xmlrpcArray, $xmlrpcString), array($xmlrpcArray));\r
+       $_xmlrpcs_listMethods_doc='This method lists all the methods that the XML-RPC server knows how to dispatch';\r
+       function _xmlrpcs_listMethods($server, $m)\r
+       {\r
+               global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;\r
+               $v=new xmlrpcval();\r
+               $dmap=$server->dmap;\r
+               $outAr=array();\r
+               for(reset($dmap); list($key, $val)=each($dmap); )\r
+               {\r
+                       $outAr[]=new xmlrpcval($key, 'string');\r
+               }\r
+               $dmap=$_xmlrpcs_dmap;\r
+               for(reset($dmap); list($key, $val)=each($dmap); )\r
+               {\r
+                       $outAr[]=new xmlrpcval($key, 'string');\r
+               }\r
+               $v->addArray($outAr);\r
+               return new xmlrpcresp($v);\r
        }\r
-       //      print "<!-- ${methName} -->\n";\r
-       if (isset($dmap[$methName])) {\r
-               if ($dmap[$methName]["signature"]) {\r
-                       $sigs=array();\r
-                       $thesigs=$dmap[$methName]["signature"];\r
-                       for($i=0; $i<sizeof($thesigs); $i++) {\r
-                               $cursig=array();\r
-                               $inSig=$thesigs[$i];\r
-                               for($j=0; $j<sizeof($inSig); $j++) {\r
-                                       $cursig[]=new xmlrpcval($inSig[$j], "string");\r
+\r
+       $_xmlrpcs_methodSignature_sig=array(array($xmlrpcArray, $xmlrpcString));\r
+       $_xmlrpcs_methodSignature_doc='Returns an array of known signatures (an array of arrays) for the method name passed. If no signatures are known, returns a none-array (test for type != array to detect missing signature)';\r
+       function _xmlrpcs_methodSignature($server, $m)\r
+       {\r
+               global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;\r
+\r
+               $methName=$m->getParam(0);\r
+               $methName=$methName->scalarval();\r
+               if (ereg("^system\.", $methName))\r
+               {\r
+                       $dmap=$_xmlrpcs_dmap; $sysCall=1;\r
+               }\r
+               else\r
+               {\r
+                       $dmap=$server->dmap; $sysCall=0;\r
+               }\r
+               //      print "<!-- ${methName} -->\n";\r
+               if (isset($dmap[$methName]))\r
+               {\r
+                       if ($dmap[$methName]['signature'])\r
+                       {\r
+                               $sigs=array();\r
+                               $thesigs=$dmap[$methName]['signature'];\r
+                               for($i=0; $i<sizeof($thesigs); $i++)\r
+                               {\r
+                                       $cursig=array();\r
+                                       $inSig=$thesigs[$i];\r
+                                       for($j=0; $j<sizeof($inSig); $j++)\r
+                                       {\r
+                                               $cursig[]=new xmlrpcval($inSig[$j], 'string');\r
+                                       }\r
+                                       $sigs[]=new xmlrpcval($cursig, 'array');\r
                                }\r
-                               $sigs[]=new xmlrpcval($cursig, "array");\r
+                               $r=new xmlrpcresp(new xmlrpcval($sigs, 'array'));\r
                        }\r
-                       $r=new xmlrpcresp(new xmlrpcval($sigs, "array"));\r
-               } else {\r
-                       $r=new xmlrpcresp(new xmlrpcval("undef", "string"));\r
+                       else\r
+                       {\r
+                               $r=new xmlrpcresp(new xmlrpcval('undef', 'string'));\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       $r=new xmlrpcresp(0,$xmlrpcerr['introspect_unknown'], $xmlrpcstr['introspect_unknown']);\r
                }\r
-       } else {\r
-                       $r=new xmlrpcresp(0,\r
-                                                 $xmlrpcerr["introspect_unknown"],\r
-                                                 $xmlrpcstr["introspect_unknown"]);\r
+               return $r;\r
        }\r
-       return $r;\r
-}\r
-\r
-$_xmlrpcs_methodHelp_sig=array(array($xmlrpcString, $xmlrpcString));\r
-$_xmlrpcs_methodHelp_doc='Returns help text if defined for the method passed, otherwise returns an empty string';\r
-function _xmlrpcs_methodHelp($server, $m) {\r
-       global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;\r
-\r
-       $methName=$m->getParam(0);\r
-       $methName=$methName->scalarval();\r
-       if (ereg("^system\.", $methName)) {\r
-               $dmap=$_xmlrpcs_dmap; $sysCall=1;\r
-       } else {\r
-               $dmap=$server->dmap; $sysCall=0;\r
+\r
+       $_xmlrpcs_methodHelp_sig=array(array($xmlrpcString, $xmlrpcString));\r
+       $_xmlrpcs_methodHelp_doc='Returns help text if defined for the method passed, otherwise returns an empty string';\r
+       function _xmlrpcs_methodHelp($server, $m)\r
+       {\r
+               global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;\r
+\r
+               $methName=$m->getParam(0);\r
+               $methName=$methName->scalarval();\r
+               if (ereg("^system\.", $methName))\r
+               {\r
+                       $dmap=$_xmlrpcs_dmap; $sysCall=1;\r
+               }\r
+               else\r
+               {\r
+                       $dmap=$server->dmap; $sysCall=0;\r
+               }\r
+               // print "<!-- ${methName} -->\n";\r
+               if (isset($dmap[$methName]))\r
+               {\r
+                       if ($dmap[$methName]['docstring'])\r
+                       {\r
+                               $r=new xmlrpcresp(new xmlrpcval($dmap[$methName]['docstring']), 'string');\r
+                       }\r
+                       else\r
+                       {\r
+                               $r=new xmlrpcresp(new xmlrpcval('', 'string'));\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       $r=new xmlrpcresp(0, $xmlrpcerr['introspect_unknown'], $xmlrpcstr['introspect_unknown']);\r
+               }\r
+               return $r;\r
        }\r
-       //      print "<!-- ${methName} -->\n";\r
-       if (isset($dmap[$methName])) {\r
-               if ($dmap[$methName]["docstring"]) {\r
-                       $r=new xmlrpcresp(new xmlrpcval($dmap[$methName]["docstring"]),\r
-                                                                                               "string");\r
-               } else {\r
-                       $r=new xmlrpcresp(new xmlrpcval("", "string"));\r
+\r
+       $_xmlrpcs_multicall_sig = array(array($xmlrpcArray, $xmlrpcArray));\r
+       $_xmlrpcs_multicall_doc = 'Boxcar multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details';\r
+\r
+       function _xmlrpcs_multicall_error($err)\r
+       {\r
+               if (is_string($err))\r
+               {\r
+                       global $xmlrpcerr, $xmlrpcstr;\r
+                       $str  = $xmlrpcstr["multicall_${err}"];\r
+                       $code = $xmlrpcerr["multicall_${err}"];\r
+               }\r
+               else\r
+               {\r
+                       $code = $err->faultCode();\r
+                       $str = $err->faultString();\r
                }\r
-       } else {\r
-                       $r=new xmlrpcresp(0,\r
-                                                 $xmlrpcerr["introspect_unknown"],\r
-                                                 $xmlrpcstr["introspect_unknown"]);\r
+               $struct['faultCode'] = new xmlrpcval($code, 'int');\r
+               $struct['faultString'] = new xmlrpcval($str, 'string');\r
+               return new xmlrpcval($struct, 'struct');\r
        }\r
-       return $r;\r
-}\r
-\r
-$_xmlrpcs_dmap=array(\r
-                                                                                "system.listMethods" =>\r
-                                                                                array("function" => "_xmlrpcs_listMethods",\r
-                                                                                                        "signature" => $_xmlrpcs_listMethods_sig,\r
-                                                                                                        "docstring" => $_xmlrpcs_listMethods_doc),\r
-                                                                                "system.methodHelp" =>\r
-                                                                                array("function" => "_xmlrpcs_methodHelp",\r
-                                                                                                        "signature" => $_xmlrpcs_methodHelp_sig,\r
-                                                                                                        "docstring" => $_xmlrpcs_methodHelp_doc),\r
-                                                                                "system.methodSignature" =>\r
-                                                                                array("function" => "_xmlrpcs_methodSignature",\r
-                                                                                                        "signature" => $_xmlrpcs_methodSignature_sig,\r
-                                                                                                        "docstring" => $_xmlrpcs_methodSignature_doc)\r
-                                                                                );\r
-\r
-$_xmlrpc_debuginfo="";\r
-function xmlrpc_debugmsg($m) {\r
-       global $_xmlrpc_debuginfo;\r
-       $_xmlrpc_debuginfo=$_xmlrpc_debuginfo . $m . "\n";\r
-}\r
-\r
-class xmlrpc_server {\r
-  var $dmap=array();\r
-\r
-  function xmlrpc_server($dispMap, $serviceNow=1) {\r
-               global $HTTP_RAW_POST_DATA;\r
-               // dispMap is a despatch array of methods\r
-               // mapped to function names and signatures\r
-               // if a method\r
-               // doesn't appear in the map then an unknown\r
-               // method error is generated\r
-               $this->dmap=$dispMap;\r
-               if ($serviceNow) {\r
-                       $this->service();\r
+\r
+       function _xmlrpcs_multicall_do_call($server, $call)\r
+       {\r
+               if ($call->kindOf() != 'struct')\r
+               {\r
+                       return _xmlrpcs_multicall_error('notstruct');\r
+               }\r
+               $methName = $call->structmem('methodName');\r
+               if (!$methName)\r
+               {\r
+                       return _xmlrpcs_multicall_error('nomethod');\r
+               }\r
+               if ($methName->kindOf() != 'scalar' || $methName->scalartyp() != 'string')\r
+               {\r
+                       return _xmlrpcs_multicall_error('notstring');\r
+               }\r
+               if ($methName->scalarval() == 'system.multicall')\r
+               {\r
+                       return _xmlrpcs_multicall_error('recursion');\r
                }\r
-  }\r
 \r
-       function serializeDebug() {\r
-               global $_xmlrpc_debuginfo;\r
-               if ($_xmlrpc_debuginfo!="") \r
-                       return "<!-- DEBUG INFO:\n\n" .\r
-                               $_xmlrpc_debuginfo . "\n-->\n";\r
-               else\r
-                       return "";\r
+               $params = $call->structmem('params');\r
+               if (!$params)\r
+               {\r
+                       return _xmlrpcs_multicall_error('noparams');\r
+               }\r
+               if ($params->kindOf() != 'array')\r
+               {\r
+                       return _xmlrpcs_multicall_error('notarray');\r
+               }\r
+               $numParams = $params->arraysize();\r
+\r
+               $msg = new xmlrpcmsg($methName->scalarval());\r
+               for ($i = 0; $i < $numParams; $i++)\r
+               {\r
+                       $msg->addParam($params->arraymem($i));\r
+               }\r
+\r
+               $result = $server->execute($msg);\r
+\r
+               if ($result->faultCode() != 0)\r
+               {\r
+                       return _xmlrpcs_multicall_error($result);    // Method returned fault.\r
+               }\r
+\r
+               return new xmlrpcval(array($result->value()), 'array');\r
+       }\r
+\r
+       function _xmlrpcs_multicall($server, $m)\r
+       {\r
+               $calls = $m->getParam(0);\r
+               $numCalls = $calls->arraysize();\r
+               $result = array();\r
+\r
+               for ($i = 0; $i < $numCalls; $i++)\r
+               {\r
+                       $call = $calls->arraymem($i);\r
+                       $result[$i] = _xmlrpcs_multicall_do_call($server, $call);\r
+               }\r
+\r
+               return new xmlrpcresp(new xmlrpcval($result, 'array'));\r
        }\r
 \r
-       function service() {\r
-               $r=$this->parseRequest();\r
-               $payload="<" . "?xml version=\"1.0\"?" . ">\n" . \r
-                       $this->serializeDebug() .\r
-                       $r->serialize();\r
-               header("Content-type: text/xml\r\nContent-length: " . \r
-                                        strlen($payload));\r
-               print $payload;\r
+       $_xmlrpcs_dmap=array(\r
+               'system.listMethods' => array(\r
+                       'function' => '_xmlrpcs_listMethods',\r
+                       'signature' => $_xmlrpcs_listMethods_sig,\r
+                       'docstring' => $_xmlrpcs_listMethods_doc),\r
+               'system.methodHelp' => array(\r
+                       'function' => '_xmlrpcs_methodHelp',\r
+                       'signature' => $_xmlrpcs_methodHelp_sig,\r
+                       'docstring' => $_xmlrpcs_methodHelp_doc),\r
+               'system.methodSignature' => array(\r
+                       'function' => '_xmlrpcs_methodSignature',\r
+                       'signature' => $_xmlrpcs_methodSignature_sig,\r
+                       'docstring' => $_xmlrpcs_methodSignature_doc),\r
+               'system.multicall' => array(\r
+                       'function' => '_xmlrpcs_multicall',\r
+                       'signature' => $_xmlrpcs_multicall_sig,\r
+                       'docstring' => $_xmlrpcs_multicall_doc\r
+               )\r
+       );\r
+\r
+       $_xmlrpc_debuginfo='';\r
+       function xmlrpc_debugmsg($m)\r
+       {\r
+               global $_xmlrpc_debuginfo;\r
+               $_xmlrpc_debuginfo=$_xmlrpc_debuginfo . $m . "\n";\r
        }\r
 \r
-       function verifySignature($in, $sig) {\r
-               for($i=0; $i<sizeof($sig); $i++) {\r
-                       // check each possible signature in turn\r
-                       $cursig=$sig[$i];\r
-                       if (sizeof($cursig)==$in->getNumParams()+1) {\r
-                               $itsOK=1;\r
-                               for($n=0; $n<$in->getNumParams(); $n++) {\r
-                                       $p=$in->getParam($n);\r
-                                       // print "<!-- $p -->\n";\r
-                                       if ($p->kindOf() == "scalar") {\r
-                                               $pt=$p->scalartyp();\r
-                                       } else {\r
-                                               $pt=$p->kindOf();\r
+       class xmlrpc_server\r
+       {\r
+               var $dmap=array();\r
+\r
+               function xmlrpc_server($dispMap='', $serviceNow=1)\r
+               {\r
+                       global $HTTP_RAW_POST_DATA;\r
+                       // dispMap is a dispatch array of methods\r
+                       // mapped to function names and signatures\r
+                       // if a method\r
+                       // doesn't appear in the map then an unknown\r
+                       // method error is generated\r
+                       /* milosch - changed to make passing dispMap optional.\r
+                        * instead, you can use the class add_to_map() function\r
+                        * to add functions manually (borrowed from SOAPX4)\r
+                        */\r
+                       if($dispMap)\r
+                       {\r
+                               $this->dmap = $dispMap;\r
+                               if($serviceNow)\r
+                               {\r
+                                       $this->service();\r
+                               }\r
+                       }\r
+               }\r
+\r
+               function serializeDebug()\r
+               {\r
+                       global $_xmlrpc_debuginfo;\r
+                       if ($_xmlrpc_debuginfo!='')\r
+                       {\r
+                               return "<!-- DEBUG INFO:\n\n" . xmlrpc_encode_entitites($_xmlrpc_debuginfo) . "\n-->\n";\r
+                       }\r
+                       else\r
+                       {\r
+                               return '';\r
+                       }\r
+               }\r
+\r
+               function service()\r
+               {\r
+                       //global $xmlrpc_defencoding;\r
+\r
+                       $r=$this->parseRequest();\r
+                       //$payload='<?xml version="1.0" encoding="' . $xmlrpc_defencoding . '"?' . '>' . "\n"\r
+                       $payload='<?xml version="1.0" ?' . '>' . "\n"\r
+                               . $this->serializeDebug()\r
+                               . $r->serialize();\r
+                       header('Content-Type: text/xml');\r
+                       header('Content-Length: ' . (int)strlen($payload));\r
+                       print $payload;\r
+               }\r
+\r
+               /*\r
+               add a method to the dispatch map\r
+               */\r
+               function add_to_map($methodname,$function,$sig,$doc)\r
+               {\r
+                       $this->dmap[$methodname] = array(\r
+                               'function'  => $function,\r
+                               'signature' => $sig,\r
+                               'docstring' => $doc\r
+                       );\r
+               }\r
+\r
+               function verifySignature($in, $sig)\r
+               {\r
+                       for($i=0; $i<sizeof($sig); $i++)\r
+                       {\r
+                               // check each possible signature in turn\r
+                               $cursig=$sig[$i];\r
+                               if (sizeof($cursig)==$in->getNumParams()+1)\r
+                               {\r
+                                       $itsOK=1;\r
+                                       for($n=0; $n<$in->getNumParams(); $n++)\r
+                                       {\r
+                                               $p=$in->getParam($n);\r
+                                               // print "<!-- $p -->\n";\r
+                                               if ($p->kindOf() == 'scalar')\r
+                                               {\r
+                                                       $pt=$p->scalartyp();\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       $pt=$p->kindOf();\r
+                                               }\r
+                                               // $n+1 as first type of sig is return type\r
+                                               if ($pt != $cursig[$n+1])\r
+                                               {\r
+                                                       $itsOK=0;\r
+                                                       $pno=$n+1; $wanted=$cursig[$n+1]; $got=$pt;\r
+                                                       break;\r
+                                               }\r
                                        }\r
-                                       // $n+1 as first type of sig is return type\r
-                                       if ($pt != $cursig[$n+1]) {\r
-                                               $itsOK=0;\r
-                                               $pno=$n+1; $wanted=$cursig[$n+1]; $got=$pt;\r
-                                               break;\r
+                                       if ($itsOK)\r
+                                       {\r
+                                               return array(1,'');\r
                                        }\r
                                }\r
-                       if ($itsOK) \r
-                               return array(1);\r
                        }\r
+                       if (isset($wanted))\r
+                               return array(0, "Wanted ${wanted}, got ${got} at param ${pno})");\r
+                       else\r
+                               return array(0, "No method signature matches number of parameters");\r
                }\r
-               return array(0, "Wanted ${wanted}, got ${got} at param ${pno})");\r
-       }\r
 \r
-  function parseRequest($data="") {\r
-       global $_xh,$HTTP_RAW_POST_DATA;\r
-       global $xmlrpcerr, $xmlrpcstr, $xmlrpcerrxml, $xmlrpc_defencoding,\r
-               $_xmlrpcs_dmap;\r
+               function parseRequest($data='')\r
+               {\r
+                       global $_xh,$HTTP_RAW_POST_DATA;\r
+                       global $xmlrpcerr, $xmlrpcstr, $xmlrpcerrxml, $xmlrpc_defencoding,\r
+                       $_xmlrpcs_dmap, $xmlrpc_internalencoding;\r
 \r
-       \r
+                       if ($data=='')\r
+                       {\r
+                               $data=$HTTP_RAW_POST_DATA;\r
+                       }\r
+            // G. Giunta 2005/02/13: we do NOT expect to receive html entities\r
+            // so we do not try to convert them into xml character entities\r
+                       //$data = xmlrpc_html_entity_xlate($data);\r
+                       $parser = xml_parser_create($xmlrpc_defencoding);\r
 \r
-       if ($data=="") {\r
-         $data=$HTTP_RAW_POST_DATA;\r
-       }\r
-       $parser = xml_parser_create($xmlrpc_defencoding);\r
-\r
-       $_xh[$parser]=array();\r
-       $_xh[$parser]['st']="";\r
-       $_xh[$parser]['cm']=0; \r
-       $_xh[$parser]['isf']=0; \r
-       $_xh[$parser]['params']=array();\r
-       $_xh[$parser]['method']="";\r
-\r
-       // decompose incoming XML into request structure\r
-\r
-       xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);\r
-       xml_set_element_handler($parser, "xmlrpc_se", "xmlrpc_ee");\r
-       xml_set_character_data_handler($parser, "xmlrpc_cd");\r
-       xml_set_default_handler($parser, "xmlrpc_dh");\r
-       if (!xml_parse($parser, $data, 1)) {\r
-         // return XML error as a faultCode\r
-         $r=new xmlrpcresp(0,\r
-                                               $xmlrpcerrxml+xml_get_error_code($parser),\r
-                                               sprintf("XML error: %s at line %d",\r
+                       $_xh[$parser]=array();\r
+                       $_xh[$parser]['st']='';\r
+                       $_xh[$parser]['cm']=0;\r
+                       $_xh[$parser]['isf']=0;\r
+                       $_xh[$parser]['params']=array();\r
+                       $_xh[$parser]['method']='';\r
+\r
+                       // decompose incoming XML into request structure\r
+\r
+                       xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);\r
+            // G. Giunta 2005/02/13: PHP internally uses ISO-8859-1, so we have to tell\r
+            // the xml parser to give us back data in the expected charset\r
+            xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $xmlrpc_internalencoding);\r
+\r
+                       xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee');\r
+                       xml_set_character_data_handler($parser, 'xmlrpc_cd');\r
+                       xml_set_default_handler($parser, 'xmlrpc_dh');\r
+                       if (!xml_parse($parser, $data, 1))\r
+                       {\r
+                               // return XML error as a faultCode\r
+                               $r=new xmlrpcresp(0,\r
+                               $xmlrpcerrxml+xml_get_error_code($parser),\r
+                               sprintf('XML error: %s at line %d',\r
                                        xml_error_string(xml_get_error_code($parser)),\r
-                                 xml_get_current_line_number($parser)));\r
-         xml_parser_free($parser);\r
-       } else {\r
-         xml_parser_free($parser);\r
-         $m=new xmlrpcmsg($_xh[$parser]['method']);\r
-         // now add parameters in\r
-         $plist="";\r
-         for($i=0; $i<sizeof($_xh[$parser]['params']); $i++) {\r
-                       //print "<!-- " . $_xh[$parser]['params'][$i]. "-->\n";\r
-                       $plist.="$i - " .  $_xh[$parser]['params'][$i]. " \n";\r
-                       eval('$m->addParam(' . $_xh[$parser]['params'][$i]. ");");\r
-         }\r
-               // uncomment this to really see what the server's getting!\r
-               // xmlrpc_debugmsg($plist);\r
-         // now to deal with the method\r
-               $methName=$_xh[$parser]['method'];\r
-               if (ereg("^system\.", $methName)) {\r
-                       $dmap=$_xmlrpcs_dmap; $sysCall=1;\r
-               } else {\r
-                       $dmap=$this->dmap; $sysCall=0;\r
+                                       xml_get_current_line_number($parser)));\r
+                               xml_parser_free($parser);\r
+                       }\r
+                       else\r
+                       {\r
+                               xml_parser_free($parser);\r
+                               $m=new xmlrpcmsg($_xh[$parser]['method']);\r
+                               // now add parameters in\r
+                               $plist='';\r
+                               $allOK = 1;\r
+                               for($i=0; $i<sizeof($_xh[$parser]['params']); $i++)\r
+                               {\r
+                                       //print "<!-- " . $_xh[$parser]['params'][$i]. "-->\n";\r
+                                       $plist.="$i - " .  $_xh[$parser]['params'][$i]. ";\n";\r
+                                       $allOK = 0;\r
+                                       @eval('$m->addParam(' . $_xh[$parser]['params'][$i]. '); $allOK=1;');\r
+                                       if (!$allOK)\r
+                                       {\r
+                                               break;\r
+                                       }\r
+                               }\r
+                               // uncomment this to really see what the server's getting!\r
+                               // xmlrpc_debugmsg($plist);\r
+                               if (!$allOK)\r
+                               {\r
+                                       $r = new xmlrpcresp(0,\r
+                                               $xmlrpcerr['incorrect_params'],\r
+                                               $xmlrpcstr['incorrect_params'] . ": xml error in param " . $i);\r
+                               }\r
+                               else\r
+                               {\r
+                                       $r = $this->execute($m);\r
+                               }\r
+                       }\r
+                       return $r;\r
                }\r
-         if (isset($dmap[$methName]['function'])) {\r
-                       // dispatch if exists\r
-                       if (isset($dmap[$methName]['signature'])) {\r
-                               $sr=$this->verifySignature($m, \r
-                                                                                                                                       $dmap[$methName]['signature'] );\r
+\r
+               function execute ($m)\r
+               {\r
+                       global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;\r
+                       // now to deal with the method\r
+                       $methName = $m->method();\r
+                       $sysCall = ereg("^system\.", $methName);\r
+                       $dmap = $sysCall ? $_xmlrpcs_dmap : $this->dmap;\r
+\r
+                       if (!isset($dmap[$methName]['function']))\r
+                       {\r
+                               // No such method\r
+                               return new xmlrpcresp(0,\r
+                                       $xmlrpcerr['unknown_method'],\r
+                                       $xmlrpcstr['unknown_method']);\r
                        }\r
-                       if ( (!isset($dmap[$methName]['signature']))\r
-                                        || $sr[0]) {\r
-                               // if no signature or correct signature\r
-                               if ($sysCall) { \r
-                                       eval('$r=' . $dmap[$methName]['function'] . \r
-                                                        '($this, $m);');\r
-                               } else {\r
-                                       eval('$r=' . $dmap[$methName]['function'] . \r
-                                                        '($m);');\r
+\r
+                       // Check signature.\r
+                       if (isset($dmap[$methName]['signature']))\r
+                       {\r
+                               $sig = $dmap[$methName]['signature'];\r
+                               list($ok, $errstr) = $this->verifySignature($m, $sig);\r
+                               if(!$ok)\r
+                               {\r
+                                       // Didn't match.\r
+                                       return new xmlrpcresp(\r
+                                               0,\r
+                                               $xmlrpcerr['incorrect_params'],\r
+                                               $xmlrpcstr['incorrect_params'] . ": ${errstr}"\r
+                                       );\r
                                }\r
-                       } else {\r
-                               $r=new xmlrpcresp(0,\r
-                                                 $xmlrpcerr["incorrect_params"],\r
-                                                 $xmlrpcstr["incorrect_params"].": ". $sr[1]);\r
                        }\r
-         } else {\r
-               // else prepare error response\r
-               $r=new xmlrpcresp(0,\r
-                                                 $xmlrpcerr["unknown_method"],\r
-                                                 $xmlrpcstr["unknown_method"]);\r
-         }\r
-       }\r
-       return $r;\r
-  }\r
 \r
-  function echoInput() {\r
-       global $HTTP_RAW_POST_DATA;\r
+                       $func = $dmap[$methName]['function'];\r
 \r
-       // a debugging routine: just echos back the input\r
-       // packet as a string value\r
+                       if ($sysCall)\r
+                       {\r
+                               return call_user_func($func, $this, $m);\r
+                       }\r
+                       else\r
+                       {\r
+                               return call_user_func($func, $m);\r
+                       }\r
+               }\r
+\r
+               function echoInput()\r
+               {\r
+                       global $HTTP_RAW_POST_DATA;\r
 \r
-       $r=new xmlrpcresp;\r
-       $r->xv=new xmlrpcval( "'Aha said I: '" . $HTTP_RAW_POST_DATA, "string");\r
-       print $r->serialize();\r
-  }\r
-}\r
+                       // a debugging routine: just echos back the input\r
+                       // packet as a string value\r
 \r
+                       $r=new xmlrpcresp;\r
+                       $r->xv=new xmlrpcval( "'Aha said I: '" . $HTTP_RAW_POST_DATA, 'string');\r
+                       print $r->serialize();\r
+               }\r
+       }\r
 ?>\r
index 8ed320e..fa969a2 100755 (executable)
@@ -1,76 +1,84 @@
 <?php\r
-/** \r
-  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) \r
-  * Copyright (C) 2002-2005 The Nucleus Group\r
-  *\r
-  * This program is free software; you can redistribute it and/or\r
-  * modify it under the terms of the GNU General Public License\r
-  * as published by the Free Software Foundation; either version 2\r
-  * of the License, or (at your option) any later version.\r
-  * (see nucleus/documentation/index.html#license for more info)\r
-  *\r
-  * $Id: server.php,v 1.5 2005-03-16 08:12:06 kimitake Exp $\r
-  * $NucleusJP: server.php,v 1.3 2005/03/12 06:19:06 kimitake Exp $\r
-  *\r
-  * This script is provides an XML-RPC [1] interface to Nucleus [2].\r
-  *\r
-  * At this time, the Blogger API [3], the metaWeblog API [4] and \r
-  * parts of the Movable Type API [5] are implemented\r
-  *\r
-  * This script uses the the 'XML-RPC for PHP v1.02' implementation [6]\r
-  * All other code was written by Wouter Demuynck [7]\r
-  *\r
-  * [1] http://www.xmlrpc.com/\r
-  * [2] http://nucleuscms.org/\r
-  * [3] http://plant.blogger.com/api/\r
-  * [4] http://www.xmlrpc.com/metaWeblogApi\r
-  * [5] http://www.movabletype.org/docs/mtmanual_programmatic.html\r
-  * [6] http://phpxmlrpc.sourceforge.net/\r
-  * [7] http://demuynck.org/\r
-  *\r
-  *\r
-  * The Blogger API: (more info in the documentation)\r
-  *\r
-  *    blogger.newPost \r
-  *    blogger.editPost \r
-  *    blogger.getUsersBlogs \r
-  *    blogger.deletePost\r
-  *    blogger.getRecentPosts\r
-  *    blogger.getPost\r
-  *    blogger.getUserInfo\r
-  *    blogger.getTemplate\r
-  *    blogger.setTemplate\r
-  *\r
-  *    Note: The getUserInfo response contains an empty 'lastname' and the full name as \r
-  *       'firstname'\r
-  * Note: Blogger API methods only affect the body field of items\r
-  *\r
-  * The metaWeblog API (more info in documentation)\r
-  *\r
-  * metaWeblog.newPost\r
-  * metaWeblog.getPost\r
-  * metaWeblog.editPost\r
-  * metaWeblog.getCategories\r
-  * metaWeblog.newMediaObject\r
-  * metaWeblog.getRecentPosts\r
-  *\r
-  * Note: metaWeblog API methods only affect the body and title fields of items. \r
-  *       the extended part is left untouched (and empty for new posts)\r
-  *\r
-  * The Movable Type API\r
-  *\r
-  * mt.supportedMethods\r
-  */\r
+/*\r
+ * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
+ * Copyright (C) 2002-2005 The Nucleus Group\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * (see nucleus/documentation/index.html#license for more info)\r
+ */\r
+\r
+/**\r
+ * This script is provides an XML-RPC [1] interface to Nucleus [2].\r
+ *\r
+ * At this time, the Blogger API [3], the metaWeblog API [4] and\r
+ * parts of the Movable Type API [5] are implemented\r
+ *\r
+ * This script uses the the 'XML-RPC for PHP v1.02' implementation [6]\r
+ * All other code was written by Wouter Demuynck [7]\r
+ *\r
+ * [1] http://www.xmlrpc.com/\r
+ * [2] http://nucleuscms.org/\r
+ * [3] http://plant.blogger.com/api/\r
+ * [4] http://www.xmlrpc.com/metaWeblogApi\r
+ * [5] http://www.movabletype.org/docs/mtmanual_programmatic.html\r
+ * [6] http://phpxmlrpc.sourceforge.net/\r
+ * [7] http://demuynck.org/\r
+ *\r
+ *\r
+ * The Blogger API: (more info in the documentation)\r
+ *\r
+ *     blogger.newPost\r
+ *     blogger.editPost\r
+ *     blogger.getUsersBlogs\r
+ *     blogger.deletePost\r
+ *     blogger.getRecentPosts\r
+ *     blogger.getPost\r
+ *     blogger.getUserInfo\r
+ *     blogger.getTemplate\r
+ *     blogger.setTemplate\r
+ *\r
+ *     Note: The getUserInfo response contains an empty 'lastname' and the full name as\r
+ *       'firstname'\r
+ * Note: Blogger API methods only affect the body field of items\r
+ *\r
+ * The metaWeblog API (more info in documentation)\r
+ *\r
+ * metaWeblog.newPost\r
+ * metaWeblog.getPost\r
+ * metaWeblog.editPost\r
+ * metaWeblog.getCategories\r
+ * metaWeblog.newMediaObject\r
+ * metaWeblog.getRecentPosts\r
+ *\r
+ * Note: metaWeblog API methods only affect the body and title fields of items.\r
+ *       the extended part is left untouched (and empty for new posts)\r
+ *\r
+ * The Movable Type API\r
+ *\r
+ * mt.supportedMethods\r
+ *\r
+ * @license http://nucleuscms.org/license.txt GNU General Public License\r
+ * @copyright Copyright (C) 2002-2005 The Nucleus Group\r
+ * @version $Id: server.php,v 1.6 2005-08-13 07:22:41 kimitake Exp $\r
+ * @version $NucleusJP: server.php,v 1.5.2.2 2005/07/03 05:16:16 kimitake Exp $\r
+ */\r
 $CONF = array();\r
 include("../../config.php");   // include Nucleus libs and code\r
 include($DIR_LIBS . "xmlrpc.inc.php");\r
 include($DIR_LIBS . "xmlrpcs.inc.php");\r
 \r
+/* define xmlrpc settings */\r
+$xmlrpc_internalencoding = 'UTF-8';\r
+$xmlrpc_defencoding = 'UTF-8';\r
+\r
 /* definition of available methods */\r
 \r
 $functionDefs = array();\r
 \r
-// load server functions \r
+// load server functions\r
 include('api_blogger.inc.php');\r
 include('api_metaweblog.inc.php');\r
 // include('api_nucleus.inc.php'); // uncomment if you still want to use the nucleus.* methods\r
@@ -92,13 +100,13 @@ function _addItem($blogid, $username, $password, $title, $body, $more, $publish,
        return _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, 0, $catname);\r
 }\r
 \r
-/** \r
+/**\r
   * Adds item to blog, with time of item given\r
   */\r
 function _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, $future, $catname = "") {\r
        // 1. login\r
        $mem = new MEMBER();\r
-       \r
+\r
        if (!$mem->login($username, $password))\r
                return _error(1,"Could not log in");\r
 \r
@@ -112,7 +120,7 @@ function _addDatedItem($blogid, $username, $password, $title, $body, $more, $pub
 \r
        // 3. calculate missing vars\r
        $blog = new BLOG($blogid);\r
-       \r
+\r
        // get category id (or id for default category when false category)\r
        $catid = $blog->getCategoryIdFromName($catname);\r
 \r
@@ -125,10 +133,11 @@ function _addDatedItem($blogid, $username, $password, $title, $body, $more, $pub
 \r
        $title = mb_convert_encoding($title, _CHARSET, "UTF-8");\r
        $body = mb_convert_encoding($body, _CHARSET, "UTF-8");\r
-       \r
+       $more = mb_convert_encoding($more, _CHARSET, "UTF-8");\r
+\r
        // 4. add to blog\r
        $itemid = $blog->additem($catid, $title, $body, $more, $blogid, $mem->getID(), $timestamp, $closed, $draft);\r
-       \r
+\r
        // [TODO] ping weblogs.com ?\r
 \r
        return new xmlrpcresp(new xmlrpcval($itemid,"string"));\r
@@ -139,21 +148,25 @@ function _addDatedItem($blogid, $username, $password, $title, $body, $more, $pub
   */\r
 function _edititem($itemid, $username, $password, $catid, $title, $body, $more, $wasdraft, $publish, $closed) {\r
        global $manager;\r
-       \r
+\r
        // 1. login\r
        $mem = new MEMBER();\r
        if (!$mem->login($username, $password))\r
                return _error(1,"Could not log in");\r
-       \r
+\r
        // 2. check if allowed to add to blog\r
        if (!$manager->existsItem($itemid,1,1))\r
                return _error(6,"No such item ($itemid)");\r
        if (!$mem->canAlterItem($itemid))\r
                return _error(7,"Not allowed to alter item");\r
-               \r
+\r
+       $title = mb_convert_encoding($title, _CHARSET, "EUC-JP,UTF-8");\r
+       $body = mb_convert_encoding($body, _CHARSET, "EUC-JP,UTF-8");\r
+       $more = mb_convert_encoding($more, _CHARSET, "EUC-JP,UTF-8");\r
+\r
        // 3. update item\r
        ITEM::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, 0);\r
-       \r
+\r
        return new xmlrpcresp(new xmlrpcval(1,"boolean"));\r
 }\r
 \r
@@ -167,20 +180,20 @@ function _getUsersBlogs($username, $password) {
                return _error(1,"Could not log in");\r
 \r
        // 2. Get list of blogs\r
-       \r
+\r
        $structarray = array();\r
        $query =  "SELECT bnumber, bname, burl"\r
-               . ' FROM '.sql_table('blog').', '.sql_table('team')\r
-               . " WHERE tblog=bnumber and tmember=" . $mem->getID()\r
-               . " ORDER BY bname";\r
+                       . ' FROM '.sql_table('blog').', '.sql_table('team')\r
+                       . " WHERE tblog=bnumber and tmember=" . $mem->getID()\r
+                       . " ORDER BY bname";\r
        $r = sql_query($query);\r
-       \r
+\r
        while ($obj = mysql_fetch_object($r)) {\r
                if ($obj->burl)\r
                        $blogurl = $obj->burl;\r
                else\r
                        $blogurl = 'http://';\r
-       \r
+\r
                $newstruct = new xmlrpcval(array(\r
                        "url" => new xmlrpcval($blogurl,"string"),\r
                        "blogid" => new xmlrpcval($obj->bnumber,"string"),\r
@@ -188,7 +201,7 @@ function _getUsersBlogs($username, $password) {
                ),'struct');\r
                array_push($structarray, $newstruct);\r
        }\r
-       \r
+\r
        return new xmlrpcresp(new xmlrpcval( $structarray , "array"));\r
 }\r
 \r
@@ -201,7 +214,7 @@ function _getUserInfo($username, $password) {
 \r
        // 3. return the info\r
        // Structure returned has nickname, userid, url, email, lastname, firstname\r
-       \r
+\r
        $newstruct = new xmlrpcval(array(\r
                "nickname" => new xmlrpcval($mem->getDisplayName(),"string"),\r
                "userid" => new xmlrpcval($mem->getID(),"string"),\r
@@ -210,9 +223,9 @@ function _getUserInfo($username, $password) {
                "lastname" => new xmlrpcval("","string"),\r
                "firstname" => new xmlrpcval($mem->getRealName(),"string")\r
        ),'struct');\r
-       \r
+\r
        return new xmlrpcresp($newstruct);\r
-       \r
+\r
 \r
 }\r
 \r
@@ -227,16 +240,16 @@ function _deleteItem($itemid, $username, $password) {
        if (!$mem->login($username, $password))\r
                return _error(1,"Could not log in");\r
 \r
-       // 2. check if allowed \r
+       // 2. check if allowed\r
        if (!$manager->existsItem($itemid,1,1))\r
                return _error(6,"No such item ($itemid)");\r
        $blogid = getBlogIDFromItemID($itemid);\r
        if (!$mem->teamRights($blogid))\r
                return _error(3,"Not a team member");\r
-               \r
+\r
        // delete the item\r
-       ITEM::delete($itemid);  \r
-       \r
+       ITEM::delete($itemid);\r
+\r
        return new xmlrpcresp(new xmlrpcval(1,"boolean"));\r
 }\r
 \r
@@ -248,18 +261,18 @@ function _getSkinPart($blogid, $username, $password, $type) {
        $mem = new MEMBER();\r
        if (!$mem->login($username, $password))\r
                return _error(1,"Could not log in");\r
-               \r
+\r
        // 2. check if allowed\r
        if (!BLOG::existsID($blogid))\r
                return _error(2,"No such blog ($blogid)");\r
        if (!$mem->teamRights($blogid))\r
                return _error(3,"Not a team member");\r
-       \r
+\r
        // 3. return skin part\r
        $blog = new BLOG($blogid);\r
        $skin = new SKIN($blog->getDefaultSkin());\r
        return new xmlrpcresp(new xmlrpcval($skin->getContent($type),"string"));\r
-       \r
+\r
 }\r
 \r
 function _setSkinPart($blogid, $username, $password, $content, $type) {\r
@@ -267,25 +280,25 @@ function _setSkinPart($blogid, $username, $password, $content, $type) {
        $mem = new MEMBER();\r
        if (!$mem->login($username, $password))\r
                return _error(1,"Could not log in");\r
-               \r
+\r
        // 2. check if allowed\r
        if (!BLOG::existsID($blogid))\r
                return _error(2,"No such blog ($blogid)");\r
        if (!$mem->teamRights($blogid))\r
                return _error(3,"Not a team member");\r
-               \r
+\r
        // 3. update skin part\r
        $blog = new BLOG($blogid);\r
        $skin = new SKIN($blog->getDefaultSkin());\r
        $skin->update($type, $content);\r
-       \r
+\r
        return new xmlrpcresp(new xmlrpcval(1,'boolean'));\r
 }\r
 \r
 /**\r
   * Some convenience methods\r
   */\r
-  \r
+\r
 function _getScalar($m, $idx) {\r
        $v = $m->getParam($idx);\r
        return $v->scalarval();\r
@@ -297,7 +310,7 @@ function _getStructVal($struct, $key) {
 }\r
 \r
 function _getArrayVal($a, $idx) {\r
-       $t = $a->arraymem(0);\r
+       $t = $a->arraymem($idx);\r
        return $t->scalarval();\r
 }\r
 \r
index 8161ffd..aca15fc 100755 (executable)
@@ -1,19 +1,11 @@
 <?php                                  // -*-c++-*-\r
-// by Edd Dumbill (C) 1999-2001\r
+// by Edd Dumbill (C) 1999-2002\r
 // <edd@usefulinc.com>\r
-// $Id: xmlrpc.inc.php,v 1.4 2005-03-08 06:49:33 kimitake Exp $\r
+// $Id: xmlrpc.inc.php,v 1.5 2005-08-13 07:24:44 kimitake Exp $\r
 // $NucleusJP$\r
 \r
-/*\r
-       Modifications made for use with Nucleus:\r
-       \r
-       renamed methods:\r
-       xmlrpc_encode -> _xmlrpc_encode\r
-       xmlrpc_decode -> _xmlrpc_decode\r
-*/\r
 \r
-\r
-// Copyright (c) 1999,2000,2001 Edd Dumbill.\r
+// Copyright (c) 1999,2000,2002 Edd Dumbill.\r
 // All rights reserved.\r
 //\r
 // Redistribution and use in source and binary forms, with or without\r
 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
 // OF THE POSSIBILITY OF SUCH DAMAGE.\r
 \r
-if (!function_exists('xml_parser_create')) {\r
-// Win 32 fix. From: "Leo West" <lwest@imaginet.fr>\r
-       if($WINDIR) {\r
-               dl("php3_xml.dll");\r
-       } else {\r
-               dl("xml.so");\r
-       }\r
-}\r
-\r
-$xmlrpcI4="i4";\r
-$xmlrpcInt="int";\r
-$xmlrpcBoolean="boolean";\r
-$xmlrpcDouble="double";\r
-$xmlrpcString="string";\r
-$xmlrpcDateTime="dateTime.iso8601";\r
-$xmlrpcBase64="base64";\r
-$xmlrpcArray="array";\r
-$xmlrpcStruct="struct";\r
-\r
-\r
-$xmlrpcTypes=array($xmlrpcI4 => 1,\r
-                                  $xmlrpcInt => 1,\r
-                                  $xmlrpcBoolean => 1,\r
-                                  $xmlrpcString => 1,\r
-                                  $xmlrpcDouble => 1,\r
-                                  $xmlrpcDateTime => 1,\r
-                                  $xmlrpcBase64 => 1,\r
-                                  $xmlrpcArray => 2,\r
-                                  $xmlrpcStruct => 3);\r
-\r
-$xmlEntities=array(     "amp" => "&",\r
-                                                                        "quot" => '"',\r
-                                                                        "lt" => "<",\r
-                                                                        "gt" => ">",\r
-                                                                        "apos" => "'");\r
-\r
-$xmlrpcerr["unknown_method"]=1;\r
-$xmlrpcstr["unknown_method"]="Unknown method";\r
-$xmlrpcerr["invalid_return"]=2;\r
-$xmlrpcstr["invalid_return"]="Invalid return payload: enabling debugging to examine incoming payload";\r
-$xmlrpcerr["incorrect_params"]=3;\r
-$xmlrpcstr["incorrect_params"]="Incorrect parameters passed to method";\r
-$xmlrpcerr["introspect_unknown"]=4;\r
-$xmlrpcstr["introspect_unknown"]="Can't introspect: method unknown";\r
-$xmlrpcerr["http_error"]=5;\r
-$xmlrpcstr["http_error"]="Didn't receive 200 OK from remote server.";\r
-$xmlrpcerr["no_data"]=6;\r
-$xmlrpcstr["no_data"]="No data received from server.";\r
-$xmlrpcerr["no_ssl"]=7;\r
-$xmlrpcstr["no_ssl"]="No SSL support compiled in.";\r
-$xmlrpcerr["curl_fail"]=8;\r
-$xmlrpcstr["curl_fail"]="CURL error";\r
-\r
-$xmlrpc_defencoding="UTF-8";\r
-\r
-$xmlrpcName="XML-RPC for PHP";\r
-$xmlrpcVersion="1.02";\r
-\r
-// let user errors start at 800\r
-$xmlrpcerruser=800; \r
-// let XML parse errors start at 100\r
-$xmlrpcerrxml=100;\r
-\r
-// formulate backslashes for escaping regexp\r
-$xmlrpc_backslash=chr(92).chr(92);\r
-\r
-// used to store state during parsing\r
-// quick explanation of components:\r
-//   st - used to build up a string for evaluation\r
-//   ac - used to accumulate values\r
-//   qt - used to decide if quotes are needed for evaluation\r
-//   cm - used to denote struct or array (comma needed)\r
-//   isf - used to indicate a fault\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
-\r
-$_xh=array();\r
-\r
-function xmlrpc_entity_decode($string) {\r
-  $top=split("&", $string);\r
-  $op="";\r
-  $i=0; \r
-  while($i<sizeof($top)) {\r
-       if (ereg("^([#a-zA-Z0-9]+);", $top[$i], $regs)) {\r
-         $op.=ereg_replace("^[#a-zA-Z0-9]+;",\r
-                                               xmlrpc_lookup_entity($regs[1]),\r
-                                                                                       $top[$i]);\r
-       } else {\r
-         if ($i==0) \r
-               $op=$top[$i]; \r
-         else\r
-               $op.="&" . $top[$i];\r
-       }\r
-       $i++;\r
-  }\r
-  return $op;\r
-}\r
-\r
-function xmlrpc_lookup_entity($ent) {\r
-  global $xmlEntities;\r
-  \r
-  if (isset($xmlEntities[strtolower($ent)]))\r
-       return $xmlEntities[strtolower($ent)];\r
-  if (ereg("^#([0-9]+)$", $ent, $regs))\r
-       return chr($regs[1]);\r
-  return "?";\r
-}\r
-\r
-function xmlrpc_se($parser, $name, $attrs) {\r
-       global $_xh, $xmlrpcDateTime, $xmlrpcString;\r
-       \r
-       switch($name) {\r
-       case "STRUCT":\r
-       case "ARRAY":\r
-         $_xh[$parser]['st'].="array(";\r
-         $_xh[$parser]['cm']++;\r
-               // this last line turns quoting off\r
-               // this means if we get an empty array we'll \r
-               // simply get a bit of whitespace in the eval\r
-               $_xh[$parser]['qt']=0;\r
-         break;\r
-       case "NAME":\r
-         $_xh[$parser]['st'].="'"; $_xh[$parser]['ac']="";\r
-         break;\r
-       case "FAULT":\r
-         $_xh[$parser]['isf']=1;\r
-         break;\r
-       case "PARAM":\r
-         $_xh[$parser]['st']="";\r
-         break;\r
-       case "VALUE":\r
-         $_xh[$parser]['st'].="new xmlrpcval("; \r
-               $_xh[$parser]['vt']=$xmlrpcString;\r
-               $_xh[$parser]['ac']="";\r
-               $_xh[$parser]['qt']=0;\r
-         $_xh[$parser]['lv']=1;\r
-         // look for a value: if this is still 1 by the\r
-         // time we reach the first data segment then the type is string\r
-         // by implication and we need to add in a quote\r
-               break;\r
-\r
-       case "I4":\r
-       case "INT":\r
-       case "STRING":\r
-       case "BOOLEAN":\r
-       case "DOUBLE":\r
-       case "DATETIME.ISO8601":\r
-       case "BASE64":\r
-         $_xh[$parser]['ac']=""; // reset the accumulator\r
-\r
-         if ($name=="DATETIME.ISO8601" || $name=="STRING") {\r
-                       $_xh[$parser]['qt']=1; \r
-                       if ($name=="DATETIME.ISO8601")\r
-                               $_xh[$parser]['vt']=$xmlrpcDateTime;\r
-         } else if ($name=="BASE64") {\r
-                       $_xh[$parser]['qt']=2;\r
-               } else {\r
-                       // No quoting is required here -- but\r
-                       // at the end of the element we must check\r
-                       // for data format errors.\r
-                       $_xh[$parser]['qt']=0;\r
-         }\r
-               break;\r
-       case "MEMBER":\r
-               $_xh[$parser]['ac']="";\r
-         break;\r
-       default:\r
-               break;\r
+       if (!function_exists('xml_parser_create'))\r
+       {\r
+               // Win 32 fix. From: 'Leo West' <lwest@imaginet.fr>\r
+               if($WINDIR)\r
+               {\r
+                       dl('php3_xml.dll');\r
+               }\r
+               else\r
+               {\r
+                       dl('xml.so');\r
+               }\r
        }\r
 \r
-       if ($name!="VALUE") $_xh[$parser]['lv']=0;\r
-}\r
-\r
-function xmlrpc_ee($parser, $name) {\r
-       global $_xh,$xmlrpcTypes,$xmlrpcString;\r
-\r
-       switch($name) {\r
-       case "STRUCT":\r
-       case "ARRAY":\r
-         if ($_xh[$parser]['cm'] && substr($_xh[$parser]['st'], -1) ==',') {\r
-               $_xh[$parser]['st']=substr($_xh[$parser]['st'],0,-1);\r
-         }\r
-         $_xh[$parser]['st'].=")";     \r
-         $_xh[$parser]['vt']=strtolower($name);\r
-         $_xh[$parser]['cm']--;\r
-         break;\r
-       case "NAME":\r
-         $_xh[$parser]['st'].= $_xh[$parser]['ac'] . "' => ";\r
-         break;\r
-       case "BOOLEAN":\r
-               // special case here: we translate boolean 1 or 0 into PHP\r
-               // constants true or false\r
-               if ($_xh[$parser]['ac']=='1') \r
-                       $_xh[$parser]['ac']="true";\r
-               else \r
-                       $_xh[$parser]['ac']="false";\r
-               $_xh[$parser]['vt']=strtolower($name);\r
-               // Drop through intentionally.\r
-       case "I4":\r
-       case "INT":\r
-       case "STRING":\r
-       case "DOUBLE":\r
-       case "DATETIME.ISO8601":\r
-       case "BASE64":\r
-         if ($_xh[$parser]['qt']==1) {\r
-                       // we use double quotes rather than single so backslashification works OK\r
-                       $_xh[$parser]['st'].="\"". $_xh[$parser]['ac'] . "\""; \r
-               } else if ($_xh[$parser]['qt']==2) {\r
-                       $_xh[$parser]['st'].="base64_decode('". $_xh[$parser]['ac'] . "')"; \r
-               } else if ($name=="BOOLEAN") {\r
-                       $_xh[$parser]['st'].=$_xh[$parser]['ac'];\r
-               } else {\r
-                       // we have an I4, INT or a DOUBLE\r
-                       // we must check that only 0123456789-.<space> are characters here\r
-                       if (!ereg("^\-?[0123456789 \t\.]+$", $_xh[$parser]['ac'])) {\r
-                               // TODO: find a better way of throwing an error\r
-                               // than this!\r
-                               error_log("XML-RPC: non numeric value received in INT or DOUBLE");\r
-                               $_xh[$parser]['st'].="ERROR_NON_NUMERIC_FOUND";\r
-                       } else {\r
-                               // it's ok, add it on\r
-                               $_xh[$parser]['st'].=$_xh[$parser]['ac'];\r
+       // G. Giunta 2005/01/29: declare global these variables,\r
+       // so that xmlrpc.inc will work even if included from within a function\r
+       // NB: it will give warnings in PHP3, so we comment it out\r
+       // Milosch: Next round, maybe we should explicitly request these via $GLOBALS where used.\r
+       if (phpversion() >= '4')\r
+       {\r
+               global $xmlrpcI4;\r
+               global $xmlrpcInt;\r
+               global $xmlrpcDouble;\r
+               global $xmlrpcString;\r
+               global $xmlrpcDateTime;\r
+               global $xmlrpcBase64;\r
+               global $xmlrpcArray;\r
+               global $xmlrpcStruct;\r
+\r
+               global $xmlrpcTypes;\r
+               global $xmlEntities;\r
+               global $xmlrpcerr;\r
+               global $xmlrpcstr;\r
+               global $xmlrpc_defencoding;\r
+               global $xmlrpc_internalencoding;\r
+               global $xmlrpcName;\r
+               global $xmlrpcVersion;\r
+               global $xmlrpcerruser;\r
+               global $xmlrpcerrxml;\r
+               global $xmlrpc_backslash;\r
+               global $_xh;\r
+       }\r
+       $xmlrpcI4='i4';\r
+       $xmlrpcInt='int';\r
+       $xmlrpcBoolean='boolean';\r
+       $xmlrpcDouble='double';\r
+       $xmlrpcString='string';\r
+       $xmlrpcDateTime='dateTime.iso8601';\r
+       $xmlrpcBase64='base64';\r
+       $xmlrpcArray='array';\r
+       $xmlrpcStruct='struct';\r
+\r
+       $xmlrpcTypes=array(\r
+               $xmlrpcI4       => 1,\r
+               $xmlrpcInt      => 1,\r
+               $xmlrpcBoolean  => 1,\r
+               $xmlrpcString   => 1,\r
+               $xmlrpcDouble   => 1,\r
+               $xmlrpcDateTime => 1,\r
+               $xmlrpcBase64   => 1,\r
+               $xmlrpcArray    => 2,\r
+               $xmlrpcStruct   => 3\r
+       );\r
+\r
+       $xmlEntities=array(\r
+               'amp'  => '&',\r
+               'quot' => '"',\r
+               'lt'   => '<',\r
+               'gt'   => '>',\r
+               'apos' => "'"\r
+       );\r
+\r
+       $xmlrpcerr['unknown_method']=1;\r
+       $xmlrpcstr['unknown_method']='Unknown method';\r
+       $xmlrpcerr['invalid_return']=2;\r
+       $xmlrpcstr['invalid_return']='Invalid return payload: enable debugging to examine incoming payload';\r
+       $xmlrpcerr['incorrect_params']=3;\r
+       $xmlrpcstr['incorrect_params']='Incorrect parameters passed to method';\r
+       $xmlrpcerr['introspect_unknown']=4;\r
+       $xmlrpcstr['introspect_unknown']="Can't introspect: method unknown";\r
+       $xmlrpcerr['http_error']=5;\r
+       $xmlrpcstr['http_error']="Didn't receive 200 OK from remote server.";\r
+       $xmlrpcerr['no_data']=6;\r
+       $xmlrpcstr['no_data']='No data received from server.';\r
+       $xmlrpcerr['no_ssl']=7;\r
+       $xmlrpcstr['no_ssl']='No SSL support compiled in.';\r
+       $xmlrpcerr['curl_fail']=8;\r
+       $xmlrpcstr['curl_fail']='CURL error';\r
+\r
+\r
+       $xmlrpcerr['multicall_notstruct'] = 9;\r
+       $xmlrpcstr['multicall_notstruct'] = 'system.multicall expected struct';\r
+       $xmlrpcerr['multicall_nomethod']  = 10;\r
+       $xmlrpcstr['multicall_nomethod']  = 'missing methodName';\r
+       $xmlrpcerr['multicall_notstring'] = 11;\r
+       $xmlrpcstr['multicall_notstring'] = 'methodName is not a string';\r
+       $xmlrpcerr['multicall_recursion'] = 12;\r
+       $xmlrpcstr['multicall_recursion'] = 'recursive system.multicall forbidden';\r
+       $xmlrpcerr['multicall_noparams']  = 13;\r
+       $xmlrpcstr['multicall_noparams']  = 'missing params';\r
+       $xmlrpcerr['multicall_notarray']  = 14;\r
+       $xmlrpcstr['multicall_notarray']  = 'params is not an array';\r
+\r
+       // The charset encoding expected by the server for received messages and\r
+       // by the client for received responses\r
+       $xmlrpc_defencoding='UTF-8';\r
+       // The encoding used by PHP.\r
+       // String values received will be converted to this.\r
+       $xmlrpc_internalencoding='ISO-8859-1';\r
+\r
+       $xmlrpcName='XML-RPC for PHP';\r
+       $xmlrpcVersion='1.1.1';\r
+\r
+       // let user errors start at 800\r
+       $xmlrpcerruser=800;\r
+       // let XML parse errors start at 100\r
+       $xmlrpcerrxml=100;\r
+\r
+       // formulate backslashes for escaping regexp\r
+       $xmlrpc_backslash=chr(92).chr(92);\r
+\r
+       // used to store state during parsing\r
+       // quick explanation of components:\r
+       //   st - used to build up a string for evaluation\r
+       //   ac - used to accumulate values\r
+       //   qt - used to decide if quotes are needed for evaluation\r
+       //   cm - used to denote struct or array (comma needed)\r
+       //   isf - used to indicate a fault\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
+\r
+       $_xh=array();\r
+\r
+       /**\r
+       * To help correct communication of non-ascii chars inside strings, regardless\r
+       * of the charset used when sending requests, parsing them, sending responses\r
+       * and parsing responses, convert all non-ascii chars present in the message\r
+       * into their equivalent 'charset entity'. Charset entities enumerated this way\r
+       * are independent of the charset encoding used to transmit them, and all XML\r
+       * parsers are bound to understand them.\r
+       */\r
+       function xmlrpc_entity_decode($string)\r
+       {\r
+               $top=split('&', $string);\r
+               $op='';\r
+               $i=0;\r
+               while($i<sizeof($top))\r
+               {\r
+                       if (ereg("^([#a-zA-Z0-9]+);", $top[$i], $regs))\r
+                       {\r
+                               $op.=ereg_replace("^[#a-zA-Z0-9]+;",\r
+                               xmlrpc_lookup_entity($regs[1]),\r
+                               $top[$i]);\r
                        }\r
+                       else\r
+                       {\r
+                               if ($i==0)\r
+                               {\r
+                                       $op=$top[$i];\r
+                               }\r
+                               else\r
+                               {\r
+                                       $op.='&' . $top[$i];\r
+                               }\r
+                       }\r
+                       $i++;\r
                }\r
-               $_xh[$parser]['ac']=""; $_xh[$parser]['qt']=0;\r
-               $_xh[$parser]['lv']=3; // indicate we've found a value\r
-         break;\r
-       case "VALUE":\r
-               // deal with a string value\r
-               if (strlen($_xh[$parser]['ac'])>0 &&\r
-                               $_xh[$parser]['vt']==$xmlrpcString) {\r
-                       $_xh[$parser]['st'].="\"". $_xh[$parser]['ac'] . "\""; \r
+               return $op;\r
+       }\r
+\r
+       function xmlrpc_lookup_entity($ent)\r
+       {\r
+               global $xmlEntities;\r
+\r
+               if (isset($xmlEntities[strtolower($ent)]))\r
+               {\r
+                       return $xmlEntities[strtolower($ent)];\r
                }\r
-               // This if() detects if no scalar was inside <VALUE></VALUE>\r
-               // and pads an empty "".\r
-               if($_xh[$parser]['st'][strlen($_xh[$parser]['st'])-1] == '(') {\r
-                       $_xh[$parser]['st'].= '""';\r
+               if (ereg("^#([0-9]+)$", $ent, $regs))\r
+               {\r
+                       return chr($regs[1]);\r
                }\r
-               $_xh[$parser]['st'].=", '" . $_xh[$parser]['vt'] . "')";\r
-               if ($_xh[$parser]['cm']) $_xh[$parser]['st'].=",";\r
-               break;\r
-       case "MEMBER":\r
-         $_xh[$parser]['ac']=""; $_xh[$parser]['qt']=0;\r
-        break;\r
-       case "DATA":\r
-         $_xh[$parser]['ac']=""; $_xh[$parser]['qt']=0;\r
-         break;\r
-       case "PARAM":\r
-         $_xh[$parser]['params'][]=$_xh[$parser]['st'];\r
-         break;\r
-       case "METHODNAME":\r
-         $_xh[$parser]['method']=ereg_replace("^[\n\r\t ]+", "", \r
-                                                                                                                                                                $_xh[$parser]['ac']);\r
-               break;\r
-       case "BOOLEAN":\r
-               // special case here: we translate boolean 1 or 0 into PHP\r
-               // constants true or false\r
-               if ($_xh[$parser]['ac']=='1') \r
-                       $_xh[$parser]['ac']="true";\r
-               else \r
-                       $_xh[$parser]['ac']="false";\r
-               $_xh[$parser]['vt']=strtolower($name);\r
-               break;\r
-       default:\r
-               break;\r
+               return '?';\r
        }\r
-       // if it's a valid type name, set the type\r
-       if (isset($xmlrpcTypes[strtolower($name)])) {\r
-               $_xh[$parser]['vt']=strtolower($name);\r
+\r
+       /**\r
+        * These entities originate from HTML specs (1.1, proposed 2.0, etc),\r
+        * and are taken directly from php-4.3.1/ext/mbstring/html_entities.c.\r
+        * Until php provides functionality to translate these entities in its\r
+        * core library, use this function.\r
+        */\r
+       function xmlrpc_html_entity_xlate($data = '')\r
+       {\r
+               $entities = array(\r
+                       "&nbsp;" => "&#160;",\r
+                       "&iexcl;" => "&#161;",\r
+                       "&cent;" => "&#162;",\r
+                       "&pound;" => "&#163;",\r
+                       "&curren;" => "&#164;",\r
+                       "&yen;" => "&#165;",\r
+                       "&brvbar;" => "&#166;",\r
+                       "&sect;" => "&#167;",\r
+                       "&uml;" => "&#168;",\r
+                       "&copy;" => "&#169;",\r
+                       "&ordf;" => "&#170;",\r
+                       "&laquo;" => "&#171;",\r
+                       "&not;" => "&#172;",\r
+                       "&shy;" => "&#173;",\r
+                       "&reg;" => "&#174;",\r
+                       "&macr;" => "&#175;",\r
+                       "&deg;" => "&#176;",\r
+                       "&plusmn;" => "&#177;",\r
+                       "&sup2;" => "&#178;",\r
+                       "&sup3;" => "&#179;",\r
+                       "&acute;" => "&#180;",\r
+                       "&micro;" => "&#181;",\r
+                       "&para;" => "&#182;",\r
+                       "&middot;" => "&#183;",\r
+                       "&cedil;" => "&#184;",\r
+                       "&sup1;" => "&#185;",\r
+                       "&ordm;" => "&#186;",\r
+                       "&raquo;" => "&#187;",\r
+                       "&frac14;" => "&#188;",\r
+                       "&frac12;" => "&#189;",\r
+                       "&frac34;" => "&#190;",\r
+                       "&iquest;" => "&#191;",\r
+                       "&Agrave;" => "&#192;",\r
+                       "&Aacute;" => "&#193;",\r
+                       "&Acirc;" => "&#194;",\r
+                       "&Atilde;" => "&#195;",\r
+                       "&Auml;" => "&#196;",\r
+                       "&Aring;" => "&#197;",\r
+                       "&AElig;" => "&#198;",\r
+                       "&Ccedil;" => "&#199;",\r
+                       "&Egrave;" => "&#200;",\r
+                       "&Eacute;" => "&#201;",\r
+                       "&Ecirc;" => "&#202;",\r
+                       "&Euml;" => "&#203;",\r
+                       "&Igrave;" => "&#204;",\r
+                       "&Iacute;" => "&#205;",\r
+                       "&Icirc;" => "&#206;",\r
+                       "&Iuml;" => "&#207;",\r
+                       "&ETH;" => "&#208;",\r
+                       "&Ntilde;" => "&#209;",\r
+                       "&Ograve;" => "&#210;",\r
+                       "&Oacute;" => "&#211;",\r
+                       "&Ocirc;" => "&#212;",\r
+                       "&Otilde;" => "&#213;",\r
+                       "&Ouml;" => "&#214;",\r
+                       "&times;" => "&#215;",\r
+                       "&Oslash;" => "&#216;",\r
+                       "&Ugrave;" => "&#217;",\r
+                       "&Uacute;" => "&#218;",\r
+                       "&Ucirc;" => "&#219;",\r
+                       "&Uuml;" => "&#220;",\r
+                       "&Yacute;" => "&#221;",\r
+                       "&THORN;" => "&#222;",\r
+                       "&szlig;" => "&#223;",\r
+                       "&agrave;" => "&#224;",\r
+                       "&aacute;" => "&#225;",\r
+                       "&acirc;" => "&#226;",\r
+                       "&atilde;" => "&#227;",\r
+                       "&auml;" => "&#228;",\r
+                       "&aring;" => "&#229;",\r
+                       "&aelig;" => "&#230;",\r
+                       "&ccedil;" => "&#231;",\r
+                       "&egrave;" => "&#232;",\r
+                       "&eacute;" => "&#233;",\r
+                       "&ecirc;" => "&#234;",\r
+                       "&euml;" => "&#235;",\r
+                       "&igrave;" => "&#236;",\r
+                       "&iacute;" => "&#237;",\r
+                       "&icirc;" => "&#238;",\r
+                       "&iuml;" => "&#239;",\r
+                       "&eth;" => "&#240;",\r
+                       "&ntilde;" => "&#241;",\r
+                       "&ograve;" => "&#242;",\r
+                       "&oacute;" => "&#243;",\r
+                       "&ocirc;" => "&#244;",\r
+                       "&otilde;" => "&#245;",\r
+                       "&ouml;" => "&#246;",\r
+                       "&divide;" => "&#247;",\r
+                       "&oslash;" => "&#248;",\r
+                       "&ugrave;" => "&#249;",\r
+                       "&uacute;" => "&#250;",\r
+                       "&ucirc;" => "&#251;",\r
+                       "&uuml;" => "&#252;",\r
+                       "&yacute;" => "&#253;",\r
+                       "&thorn;" => "&#254;",\r
+                       "&yuml;" => "&#255;",\r
+                       "&OElig;" => "&#338;",\r
+                       "&oelig;" => "&#339;",\r
+                       "&Scaron;" => "&#352;",\r
+                       "&scaron;" => "&#353;",\r
+                       "&Yuml;" => "&#376;",\r
+                       "&fnof;" => "&#402;",\r
+                       "&circ;" => "&#710;",\r
+                       "&tilde;" => "&#732;",\r
+                       "&Alpha;" => "&#913;",\r
+                       "&Beta;" => "&#914;",\r
+                       "&Gamma;" => "&#915;",\r
+                       "&Delta;" => "&#916;",\r
+                       "&Epsilon;" => "&#917;",\r
+                       "&Zeta;" => "&#918;",\r
+                       "&Eta;" => "&#919;",\r
+                       "&Theta;" => "&#920;",\r
+                       "&Iota;" => "&#921;",\r
+                       "&Kappa;" => "&#922;",\r
+                       "&Lambda;" => "&#923;",\r
+                       "&Mu;" => "&#924;",\r
+                       "&Nu;" => "&#925;",\r
+                       "&Xi;" => "&#926;",\r
+                       "&Omicron;" => "&#927;",\r
+                       "&Pi;" => "&#928;",\r
+                       "&Rho;" => "&#929;",\r
+                       "&Sigma;" => "&#931;",\r
+                       "&Tau;" => "&#932;",\r
+                       "&Upsilon;" => "&#933;",\r
+                       "&Phi;" => "&#934;",\r
+                       "&Chi;" => "&#935;",\r
+                       "&Psi;" => "&#936;",\r
+                       "&Omega;" => "&#937;",\r
+                       "&beta;" => "&#946;",\r
+                       "&gamma;" => "&#947;",\r
+                       "&delta;" => "&#948;",\r
+                       "&epsilon;" => "&#949;",\r
+                       "&zeta;" => "&#950;",\r
+                       "&eta;" => "&#951;",\r
+                       "&theta;" => "&#952;",\r
+                       "&iota;" => "&#953;",\r
+                       "&kappa;" => "&#954;",\r
+                       "&lambda;" => "&#955;",\r
+                       "&mu;" => "&#956;",\r
+                       "&nu;" => "&#957;",\r
+                       "&xi;" => "&#958;",\r
+                       "&omicron;" => "&#959;",\r
+                       "&pi;" => "&#960;",\r
+                       "&rho;" => "&#961;",\r
+                       "&sigmaf;" => "&#962;",\r
+                       "&sigma;" => "&#963;",\r
+                       "&tau;" => "&#964;",\r
+                       "&upsilon;" => "&#965;",\r
+                       "&phi;" => "&#966;",\r
+                       "&chi;" => "&#967;",\r
+                       "&psi;" => "&#968;",\r
+                       "&omega;" => "&#969;",\r
+                       "&thetasym;" => "&#977;",\r
+                       "&upsih;" => "&#978;",\r
+                       "&piv;" => "&#982;",\r
+                       "&ensp;" => "&#8194;",\r
+                       "&emsp;" => "&#8195;",\r
+                       "&thinsp;" => "&#8201;",\r
+                       "&zwnj;" => "&#8204;",\r
+                       "&zwj;" => "&#8205;",\r
+                       "&lrm;" => "&#8206;",\r
+                       "&rlm;" => "&#8207;",\r
+                       "&ndash;" => "&#8211;",\r
+                       "&mdash;" => "&#8212;",\r
+                       "&lsquo;" => "&#8216;",\r
+                       "&rsquo;" => "&#8217;",\r
+                       "&sbquo;" => "&#8218;",\r
+                       "&ldquo;" => "&#8220;",\r
+                       "&rdquo;" => "&#8221;",\r
+                       "&bdquo;" => "&#8222;",\r
+                       "&dagger;" => "&#8224;",\r
+                       "&Dagger;" => "&#8225;",\r
+                       "&bull;" => "&#8226;",\r
+                       "&hellip;" => "&#8230;",\r
+                       "&permil;" => "&#8240;",\r
+                       "&prime;" => "&#8242;",\r
+                       "&Prime;" => "&#8243;",\r
+                       "&lsaquo;" => "&#8249;",\r
+                       "&rsaquo;" => "&#8250;",\r
+                       "&oline;" => "&#8254;",\r
+                       "&frasl;" => "&#8260;",\r
+                       "&euro;" => "&#8364;",\r
+                       "&weierp;" => "&#8472;",\r
+                       "&image;" => "&#8465;",\r
+                       "&real;" => "&#8476;",\r
+                       "&trade;" => "&#8482;",\r
+                       "&alefsym;" => "&#8501;",\r
+                       "&larr;" => "&#8592;",\r
+                       "&uarr;" => "&#8593;",\r
+                       "&rarr;" => "&#8594;",\r
+                       "&darr;" => "&#8595;",\r
+                       "&harr;" => "&#8596;",\r
+                       "&crarr;" => "&#8629;",\r
+                       "&lArr;" => "&#8656;",\r
+                       "&uArr;" => "&#8657;",\r
+                       "&rArr;" => "&#8658;",\r
+                       "&dArr;" => "&#8659;",\r
+                       "&hArr;" => "&#8660;",\r
+                       "&forall;" => "&#8704;",\r
+                       "&part;" => "&#8706;",\r
+                       "&exist;" => "&#8707;",\r
+                       "&empty;" => "&#8709;",\r
+                       "&nabla;" => "&#8711;",\r
+                       "&isin;" => "&#8712;",\r
+                       "&notin;" => "&#8713;",\r
+                       "&ni;" => "&#8715;",\r
+                       "&prod;" => "&#8719;",\r
+                       "&sum;" => "&#8721;",\r
+                       "&minus;" => "&#8722;",\r
+                       "&lowast;" => "&#8727;",\r
+                       "&radic;" => "&#8730;",\r
+                       "&prop;" => "&#8733;",\r
+                       "&infin;" => "&#8734;",\r
+                       "&ang;" => "&#8736;",\r
+                       "&and;" => "&#8743;",\r
+                       "&or;" => "&#8744;",\r
+                       "&cap;" => "&#8745;",\r
+                       "&cup;" => "&#8746;",\r
+                       "&int;" => "&#8747;",\r
+                       "&there4;" => "&#8756;",\r
+                       "&sim;" => "&#8764;",\r
+                       "&cong;" => "&#8773;",\r
+                       "&asymp;" => "&#8776;",\r
+                       "&ne;" => "&#8800;",\r
+                       "&equiv;" => "&#8801;",\r
+                       "&le;" => "&#8804;",\r
+                       "&ge;" => "&#8805;",\r
+                       "&sub;" => "&#8834;",\r
+                       "&sup;" => "&#8835;",\r
+                       "&nsub;" => "&#8836;",\r
+                       "&sube;" => "&#8838;",\r
+                       "&supe;" => "&#8839;",\r
+                       "&oplus;" => "&#8853;",\r
+                       "&otimes;" => "&#8855;",\r
+                       "&perp;" => "&#8869;",\r
+                       "&sdot;" => "&#8901;",\r
+                       "&lceil;" => "&#8968;",\r
+                       "&rceil;" => "&#8969;",\r
+                       "&lfloor;" => "&#8970;",\r
+                       "&rfloor;" => "&#8971;",\r
+                       "&lang;" => "&#9001;",\r
+                       "&rang;" => "&#9002;",\r
+                       "&loz;" => "&#9674;",\r
+                       "&spades;" => "&#9824;",\r
+                       "&clubs;" => "&#9827;",\r
+                       "&hearts;" => "&#9829;",\r
+                       "&diams;" => "&#9830;");\r
+               return strtr($data, $entities);\r
        }\r
-       \r
-}\r
-\r
-function xmlrpc_cd($parser, $data)\r
-{      \r
-  global $_xh, $xmlrpc_backslash;\r
-\r
-  //if (ereg("^[\n\r \t]+$", $data)) return;\r
-  // print "adding [${data}]\n";\r
-\r
-       if ($_xh[$parser]['lv']!=3) {\r
-               // "lookforvalue==3" means that we've found an entire value\r
-               // and should discard any further character data\r
-               if ($_xh[$parser]['lv']==1) {  \r
-                       // if we've found text and we're just in a <value> then\r
-                       // turn quoting on, as this will be a string\r
-                       $_xh[$parser]['qt']=1; \r
-                       // and say we've found a value\r
-                       $_xh[$parser]['lv']=2; \r
+\r
+       function xmlrpc_encode_entitites($data) \r
+       {\r
+               $length = strlen($data);\r
+               $escapeddata = "";\r
+               for($position = 0; $position < $length; $position++)\r
+               {\r
+                       $character = substr($data, $position, 1);\r
+                       $code = Ord($character);\r
+                       switch($code) {\r
+                               case 34:\r
+                               $character = "&quot;";\r
+                               break;\r
+                               case 38:\r
+                               $character = "&amp;";\r
+                               break;\r
+                               case 39:\r
+                               $character = "&apos;";\r
+                               break;\r
+                               case 60:\r
+                               $character = "&lt;";\r
+                               break;\r
+                               case 62:\r
+                               $character = "&gt;";\r
+                               break;\r
+                               default:\r
+                               if ($code < 32 || $code > 159)\r
+                                       $character = ("&#".strval($code).";");\r
+                               break;\r
+                       }\r
+                       $escapeddata .= $character;\r
                }\r
-       // replace characters that eval would\r
-       // do special things with\r
-       $_xh[$parser]['ac'].=str_replace('$', '\$',\r
-               str_replace('"', '\"', str_replace(chr(92),\r
-                       $xmlrpc_backslash, $data)));\r
+               return $escapeddata;\r
        }\r
-}\r
-\r
-function xmlrpc_dh($parser, $data)\r
-{\r
-  global $_xh;\r
-  if (substr($data, 0, 1) == "&" && substr($data, -1, 1) == ";") {\r
-               if ($_xh[$parser]['lv']==1) {  \r
-                       $_xh[$parser]['qt']=1; \r
-                       $_xh[$parser]['lv']=2; \r
+\r
+       function xmlrpc_se($parser, $name, $attrs)\r
+       {\r
+               global $_xh, $xmlrpcDateTime, $xmlrpcString;\r
+\r
+               switch($name)\r
+               {\r
+                       case 'STRUCT':\r
+                       case 'ARRAY':\r
+                               $_xh[$parser]['st'].='array(';\r
+                               $_xh[$parser]['cm']++;\r
+                               // this last line turns quoting off\r
+                               // this means if we get an empty array we'll\r
+                               // simply get a bit of whitespace in the eval\r
+                               $_xh[$parser]['qt']=0;\r
+                               break;\r
+                       case 'NAME':\r
+                               $_xh[$parser]['st'].='"';\r
+                               $_xh[$parser]['ac']='';\r
+                               break;\r
+                       case 'FAULT':\r
+                               $_xh[$parser]['isf']=1;\r
+                               break;\r
+                       case 'PARAM':\r
+                               $_xh[$parser]['st']='';\r
+                               break;\r
+                       case 'VALUE':\r
+                               $_xh[$parser]['st'].='new xmlrpcval(';\r
+                               $_xh[$parser]['vt']=$xmlrpcString;\r
+                               $_xh[$parser]['ac']='';\r
+                               $_xh[$parser]['qt']=0;\r
+                               $_xh[$parser]['lv']=1;\r
+                               // look for a value: if this is still 1 by the\r
+                               // time we reach the first data segment then the type is string\r
+                               // by implication and we need to add in a quote\r
+                               break;\r
+                       case 'I4':\r
+                       case 'INT':\r
+                       case 'STRING':\r
+                       case 'BOOLEAN':\r
+                       case 'DOUBLE':\r
+                       case 'DATETIME.ISO8601':\r
+                       case 'BASE64':\r
+                               $_xh[$parser]['ac']=''; // reset the accumulator\r
+\r
+                               if ($name=='DATETIME.ISO8601' || $name=='STRING')\r
+                               {\r
+                                       $_xh[$parser]['qt']=1;\r
+                                       if ($name=='DATETIME.ISO8601')\r
+                                       {\r
+                                               $_xh[$parser]['vt']=$xmlrpcDateTime;\r
+                                       }\r
+                               }\r
+                               elseif ($name=='BASE64')\r
+                               {\r
+                                       $_xh[$parser]['qt']=2;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // No quoting is required here -- but\r
+                                       // at the end of the element we must check\r
+                                       // for data format errors.\r
+                                       $_xh[$parser]['qt']=0;\r
+                               }\r
+                               break;\r
+                       case 'MEMBER':\r
+                               $_xh[$parser]['ac']='';\r
+                               break;\r
+                       default:\r
+                               break;\r
                }\r
-               $_xh[$parser]['ac'].=str_replace('$', '\$',\r
-                               str_replace('"', '\"', str_replace(chr(92),\r
-                                       $xmlrpc_backslash, $data)));\r
-  }\r
-}\r
-\r
-class xmlrpc_client {\r
-  var $path;\r
-  var $server;\r
-  var $port;\r
-  var $errno;\r
-  var $errstring;\r
-  var $debug=0;\r
-  var $username="";\r
-  var $password="";\r
-  var $cert="";\r
-  var $certpass="";\r
-  \r
-  function xmlrpc_client($path, $server, $port=0) {\r
-    $this->port=$port; $this->server=$server; $this->path=$path;\r
-  }\r
-\r
-  function setDebug($in) {\r
-               if ($in) { \r
-                       $this->debug=1;\r
-               } else {\r
-                       $this->debug=0;\r
+\r
+               if ($name!='VALUE')\r
+               {\r
+                       $_xh[$parser]['lv']=0;\r
                }\r
-  }\r
-\r
-  function setCredentials($u, $p) {\r
-    $this->username=$u;\r
-    $this->password=$p;\r
-  }\r
-\r
-  function setCertificate($cert, $certpass) {\r
-    $this->cert = $cert;\r
-    $this->certpass = $certpass;\r
-  }\r
-\r
-  function send($msg, $timeout=0, $method='http') {\r
-    // where msg is an xmlrpcmsg\r
-    $msg->debug=$this->debug;\r
\r
-    if ($method == 'https') {\r
-      return $this->sendPayloadHTTPS($msg,\r
-                                    $this->server,\r
-                                    $this->port, $timeout,\r
-                                    $this->username, $this->password,\r
-                                    $this->cert,\r
-                                    $this->certpass);\r
-    } else {\r
-      return $this->sendPayloadHTTP10($msg, $this->server, $this->port,\r
-                                     $timeout, $this->username, \r
-                                     $this->password);\r
-    }\r
-  }\r
-\r
-  function sendPayloadHTTP10($msg, $server, $port, $timeout=0,\r
-                            $username="", $password="") {\r
-    if ($port==0) $port=80;\r
-    if($timeout>0)\r
-      $fp=@fsockopen($server, $port,\r
-                   $this->errno, $this->errstr, $timeout);\r
-    else\r
-      $fp=@fsockopen($server, $port,\r
-                   $this->errno, $this->errstr);\r
-    if (!$fp) {   \r
-      return 0;\r
-    }\r
-    // Only create the payload if it was not created previously\r
-    if(empty($msg->payload)) $msg->createPayload();\r
-    \r
-    // thanks to Grant Rauscher <grant7@firstworld.net>\r
-    // for this\r
-    $credentials="";\r
-    if ($username!="") {\r
-      $credentials="Authorization: Basic " .\r
-       base64_encode($username . ":" . $password) . "\r\n";\r
-    }\r
-    \r
-    $op= "POST " . $this->path. " HTTP/1.0\r\nUser-Agent: PHP XMLRPC 1.0\r\n" .\r
-      "Host: ". $this->server  . "\r\n" .\r
-      $credentials . \r
-      "Content-Type: text/xml\r\nContent-Length: " .\r
-      strlen($msg->payload) . "\r\n\r\n" .\r
-      $msg->payload;\r
-    \r
-    if (!fputs($fp, $op, strlen($op))) {\r
-      $this->errstr="Write error";\r
-      return 0;\r
-    }\r
-    $resp=$msg->parseResponseFile($fp);\r
-    fclose($fp);\r
-    return $resp;\r
-  }\r
-\r
-  // contributed by Justi