Implement interface ArrayAccess in the Value class
[plcapi.git] / debugger / action.php
index 69f66e0..3b01444 100644 (file)
@@ -8,6 +8,9 @@
  * @todo use ob_start to catch debug info and echo it AFTER method call results?
  * @todo be smarter in creating client stub for proxy/auth cases: only set appropriate property of client obj
  **/
+
+header('Content-Type: text/html; charset=utf-8');
+
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@@ -104,11 +107,11 @@ if ($action) {
         if (!class_exists('jsonrpc_client')) {
             die('Error: to debug the jsonrpc protocol the jsonrpc.inc file is needed');
         }
-        $clientClass = 'PhpJsRpc\client';
-        $requestClass = 'PhpJsRpc\request';
+        $clientClass = 'PhpJsRpc\Client';
+        $requestClass = 'PhpJsRpc\Request';
         $protoName = 'JSONRPC';
     } else {
-        $clientClass = 'PhpXmlRpc\client';
+        $clientClass = 'PhpXmlRpc\Client';
         $requestClass = 'PhpXmlRpc\Request';
         $protoName = 'XMLRPC';
     }
@@ -226,7 +229,7 @@ if ($action) {
                     }
                 }
             } else {
-                $msg[0]->payload = $msg[0]->xml_header() .
+                $msg[0]->payload = $msg[0]->xml_header($inputcharset) .
                     '<methodName>' . $method . "</methodName>\n<params>" .
                     $payload .
                     "</params>\n" . $msg[0]->xml_footer();
@@ -239,7 +242,7 @@ if ($action) {
 
     // Before calling execute, echo out brief description of action taken + date and time ???
     // this gives good user feedback for long-running methods...
-    echo '<h2>' . htmlspecialchars($actionname) . ' on server ' . htmlspecialchars($server) . " ...</h2>\n";
+    echo '<h2>' . htmlspecialchars($actionname, ENT_COMPAT, $inputcharset) . ' on server ' . htmlspecialchars($server, ENT_COMPAT, $inputcharset) . " ...</h2>\n";
     flush();
 
     $response = null;
@@ -248,8 +251,7 @@ if ($action) {
         echo '<div class="dbginfo"><h2>Debug info:</h2>';
     }  /// @todo use ob_start instead
     $resp = array();
-    $mtime = explode(' ', microtime());
-    $time = (float)$mtime[0] + (float)$mtime[1];
+    $time = microtime(true);
     foreach ($msg as $message) {
         // catch errors: for older xmlrpc libs, send does not return by ref
         @$response = $client->send($message, $timeout, $httpprotocol);
@@ -258,8 +260,7 @@ if ($action) {
             break;
         }
     }
-    $mtime = explode(' ', microtime());
-    $time = (float)$mtime[0] + (float)$mtime[1] - $time;
+    $time = microtime(true) - $time;
     if ($debug) {
         echo "</div>\n";
     }
@@ -267,14 +268,14 @@ if ($action) {
     if ($response) {
         if ($response->faultCode()) {
             // call failed! echo out error msg!
-            //echo '<h2>'.htmlspecialchars($actionname).' on server '.htmlspecialchars($server).'</h2>';
+            //echo '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
             echo "<h3>$protoName call FAILED!</h3>\n";
-            echo "<p>Fault code: [" . htmlspecialchars($response->faultCode()) .
-                "] Reason: '" . htmlspecialchars($response->faultString()) . "'</p>\n";
+            echo "<p>Fault code: [" . htmlspecialchars($response->faultCode(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
+                "] Reason: '" . htmlspecialchars($response->faultString(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "'</p>\n";
             echo(strftime("%d/%b/%Y:%H:%M:%S\n"));
         } else {
             // call succeeded: parse results
-            //echo '<h2>'.htmlspecialchars($actionname).' on server '.htmlspecialchars($server).'</h2>';
+            //echo '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
             printf("<h3>%s call(s) OK (%.2f secs.)</h3>\n", $protoName, $time);
             echo(strftime("%d/%b/%Y:%H:%M:%S\n"));
 
@@ -283,37 +284,38 @@ if ($action) {
 
                     $v = $response->value();
                     if ($v->kindOf() == "array") {
-                        $max = $v->arraysize();
+                        $max = $v->count();
                         echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
-                        echo "<thead>\n<tr><th>Method</th><th>Description</th></tr>\n</thead>\n<tbody>\n";
-                        for ($i = 0; $i < $max; $i++) {
-                            $rec = $v->arraymem($i);
+                        echo "<thead>\n<tr><th>Method ($max)</th><th>Description</th></tr>\n</thead>\n<tbody>\n";
+                        //for ($i = 0; $i < $max; $i++) {
+                        foreach($v as $i => $rec) {
+                            //$rec = $v->arraymem($i);
                             if ($i % 2) {
                                 $class = ' class="oddrow"';
                             } else {
                                 $class = ' class="evenrow"';
                             }
-                            echo("<tr><td$class>" . htmlspecialchars($rec->scalarval()) . "</td><td$class><form action=\"controller.php\" method=\"get\" target=\"frmcontroller\">" .
-                                "<input type=\"hidden\" name=\"host\" value=\"" . htmlspecialchars($host) . "\" />" .
-                                "<input type=\"hidden\" name=\"port\" value=\"" . htmlspecialchars($port) . "\" />" .
-                                "<input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars($path) . "\" />" .
-                                "<input type=\"hidden\" name=\"id\" value=\"" . htmlspecialchars($id) . "\" />" .
+                            echo("<tr><td$class>" . htmlspecialchars($rec->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "</td><td$class><form action=\"controller.php\" method=\"get\" target=\"frmcontroller\">" .
+                                "<input type=\"hidden\" name=\"host\" value=\"" . htmlspecialchars($host, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"port\" value=\"" . htmlspecialchars($port, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars($path, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"id\" value=\"" . htmlspecialchars($id, ENT_COMPAT, $inputcharset) . "\" />" .
                                 "<input type=\"hidden\" name=\"debug\" value=\"$debug\" />" .
-                                "<input type=\"hidden\" name=\"username\" value=\"" . htmlspecialchars($username) . "\" />" .
-                                "<input type=\"hidden\" name=\"password\" value=\"" . htmlspecialchars($password) . "\" />" .
+                                "<input type=\"hidden\" name=\"username\" value=\"" . htmlspecialchars($username, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"password\" value=\"" . htmlspecialchars($password, ENT_COMPAT, $inputcharset) . "\" />" .
                                 "<input type=\"hidden\" name=\"authtype\" value=\"$authtype\" />" .
                                 "<input type=\"hidden\" name=\"verifyhost\" value=\"$verifyhost\" />" .
                                 "<input type=\"hidden\" name=\"verifypeer\" value=\"$verifypeer\" />" .
-                                "<input type=\"hidden\" name=\"cainfo\" value=\"" . htmlspecialchars($cainfo) . "\" />" .
-                                "<input type=\"hidden\" name=\"proxy\" value=\"" . htmlspecialchars($proxy) . "\" />" .
-                                "<input type=\"hidden\" name=\"proxyuser\" value=\"" . htmlspecialchars($proxyuser) . "\" />" .
-                                "<input type=\"hidden\" name=\"proxypwd\" value=\"" . htmlspecialchars($proxypwd) . "\" />" .
+                                "<input type=\"hidden\" name=\"cainfo\" value=\"" . htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"proxy\" value=\"" . htmlspecialchars($proxy, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"proxyuser\" value=\"" . htmlspecialchars($proxyuser, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"proxypwd\" value=\"" . htmlspecialchars($proxypwd, ENT_COMPAT, $inputcharset) . "\" />" .
                                 "<input type=\"hidden\" name=\"responsecompression\" value=\"$responsecompression\" />" .
                                 "<input type=\"hidden\" name=\"requestcompression\" value=\"$requestcompression\" />" .
-                                "<input type=\"hidden\" name=\"clientcookies\" value=\"" . htmlspecialchars($clientcookies) . "\" />" .
+                                "<input type=\"hidden\" name=\"clientcookies\" value=\"" . htmlspecialchars($clientcookies, ENT_COMPAT, $inputcharset) . "\" />" .
                                 "<input type=\"hidden\" name=\"protocol\" value=\"$protocol\" />" .
-                                "<input type=\"hidden\" name=\"timeout\" value=\"" . htmlspecialchars($timeout) . "\" />" .
-                                "<input type=\"hidden\" name=\"method\" value=\"" . $rec->scalarval() . "\" />" .
+                                "<input type=\"hidden\" name=\"timeout\" value=\"" . htmlspecialchars($timeout, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"method\" value=\"" . htmlspecialchars($rec->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "\" />" .
                                 "<input type=\"hidden\" name=\"wstype\" value=\"$wstype\" />" .
                                 "<input type=\"hidden\" name=\"action\" value=\"describe\" />" .
                                 "<input type=\"hidden\" name=\"run\" value=\"now\" />" .
@@ -343,37 +345,56 @@ if ($action) {
                     $r2 = $resp[1]->value();
 
                     echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
-                    echo "<thead>\n<tr><th>Method</th><th>" . htmlspecialchars($method) . "</th><th>&nbsp;</th><th>&nbsp;</th></tr>\n</thead>\n<tbody>\n";
-                    $desc = htmlspecialchars($r1->scalarval());
+                    echo "<thead>\n<tr><th>Method</th><th>" . htmlspecialchars($method, ENT_COMPAT, $inputcharset) . "</th><th>&nbsp;</th><th>&nbsp;</th></tr>\n</thead>\n<tbody>\n";
+                    $desc = htmlspecialchars($r1->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding);
                     if ($desc == "") {
                         $desc = "-";
                     }
                     echo "<tr><td class=\"evenrow\">Description</td><td colspan=\"3\" class=\"evenrow\">$desc</td></tr>\n";
-                    $payload = "";
-                    $alt_payload = "";
+
                     if ($r2->kindOf() != "array") {
                         echo "<tr><td class=\"oddrow\">Signature</td><td class=\"oddrow\">Unknown</td><td class=\"oddrow\">&nbsp;</td></tr>\n";
                     } else {
-                        for ($i = 0; $i < $r2->arraysize(); $i++) {
+                        //for ($i = 0; $i < $r2->arraysize(); $i++) {
+                        foreach($r2 as $i => $x) {
+                            $payload = "";
+                            $alt_payload = "";
                             if ($i + 1 % 2) {
                                 $class = ' class="oddrow"';
                             } else {
                                 $class = ' class="evenrow"';
                             }
                             echo "<tr><td$class>Signature&nbsp;" . ($i + 1) . "</td><td$class>";
-                            $x = $r2->arraymem($i);
+                            //$x = $r2->arraymem($i);
                             if ($x->kindOf() == "array") {
-                                $ret = $x->arraymem(0);
-                                echo "<code>OUT:&nbsp;" . htmlspecialchars($ret->scalarval()) . "<br />IN: (";
-                                if ($x->arraysize() > 1) {
-                                    for ($k = 1; $k < $x->arraysize(); $k++) {
-                                        $y = $x->arraymem($k);
-                                        echo $y->scalarval();
+                                //$ret = $x->arraymem(0);
+                                $ret = $x[0];
+                                echo "<code>OUT:&nbsp;" . htmlspecialchars($ret->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "<br />IN: (";
+                                if ($x->count() > 1) {
+                                    foreach($x as $k => $y) {
+                                        if ($k == 0) continue;
+                                    //for ($k = 1; $k < $x->arraysize(); $k++) {
+                                        //$y = $x->arraymem($k);
+                                        echo htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding);
                                         if ($wstype != 1) {
-                                            $payload = $payload . '<param><value><' . htmlspecialchars($y->scalarval()) . '></' . htmlspecialchars($y->scalarval()) . "></value></param>\n";
+                                            $type = $y->scalarval();
+                                            $payload .= '<param><value>';
+                                            switch($type) {
+                                                case 'undefined':
+                                                    break;
+                                                case 'null';
+                                                    $type = 'nil';
+                                                    // fall thru intentionally
+                                                default:
+                                                    $payload .= '<' .
+                                                        htmlspecialchars($type, ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
+                                                        '></' . htmlspecialchars($type, ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
+                                                        '>';
+                                            }
+                                            $payload .= "</value></param>\n";
                                         }
                                         $alt_payload .= $y->scalarval();
-                                        if ($k < $x->arraysize() - 1) {
+                                        if ($k < $x->count() - 1) {
                                             $alt_payload .= ';';
                                             echo ", ";
                                         }
@@ -387,28 +408,28 @@ if ($action) {
                             // button to test this method
                             //$payload="<methodCall>\n<methodName>$method</methodName>\n<params>\n$payload</params>\n</methodCall>";
                             echo "<td$class><form action=\"controller.php\" target=\"frmcontroller\" method=\"get\">" .
-                                "<input type=\"hidden\" name=\"host\" value=\"" . htmlspecialchars($host) . "\" />" .
-                                "<input type=\"hidden\" name=\"port\" value=\"" . htmlspecialchars($port) . "\" />" .
-                                "<input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars($path) . "\" />" .
-                                "<input type=\"hidden\" name=\"id\" value=\"" . htmlspecialchars($id) . "\" />" .
+                                "<input type=\"hidden\" name=\"host\" value=\"" . htmlspecialchars($host, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"port\" value=\"" . htmlspecialchars($port, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars($path, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"id\" value=\"" . htmlspecialchars($id, ENT_COMPAT, $inputcharset) . "\" />" .
                                 "<input type=\"hidden\" name=\"debug\" value=\"$debug\" />" .
-                                "<input type=\"hidden\" name=\"username\" value=\"" . htmlspecialchars($username) . "\" />" .
-                                "<input type=\"hidden\" name=\"password\" value=\"" . htmlspecialchars($password) . "\" />" .
+                                "<input type=\"hidden\" name=\"username\" value=\"" . htmlspecialchars($username, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"password\" value=\"" . htmlspecialchars($password, ENT_COMPAT, $inputcharset) . "\" />" .
                                 "<input type=\"hidden\" name=\"authtype\" value=\"$authtype\" />" .
                                 "<input type=\"hidden\" name=\"verifyhost\" value=\"$verifyhost\" />" .
                                 "<input type=\"hidden\" name=\"verifypeer\" value=\"$verifypeer\" />" .
-                                "<input type=\"hidden\" name=\"cainfo\" value=\"" . htmlspecialchars($cainfo) . "\" />" .
-                                "<input type=\"hidden\" name=\"proxy\" value=\"" . htmlspecialchars($proxy) . "\" />" .
-                                "<input type=\"hidden\" name=\"proxyuser\" value=\"" . htmlspecialchars($proxyuser) . "\" />" .
-                                "<input type=\"hidden\" name=\"proxypwd\" value=\"" . htmlspecialchars($proxypwd) . "\" />" .
+                                "<input type=\"hidden\" name=\"cainfo\" value=\"" . htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"proxy\" value=\"" . htmlspecialchars($proxy, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"proxyuser\" value=\"" . htmlspecialchars($proxyuser, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"proxypwd\" value=\"" . htmlspecialchars($proxypwd, ENT_COMPAT, $inputcharset) . "\" />" .
                                 "<input type=\"hidden\" name=\"responsecompression\" value=\"$responsecompression\" />" .
                                 "<input type=\"hidden\" name=\"requestcompression\" value=\"$requestcompression\" />" .
-                                "<input type=\"hidden\" name=\"clientcookies\" value=\"" . htmlspecialchars($clientcookies) . "\" />" .
+                                "<input type=\"hidden\" name=\"clientcookies\" value=\"" . htmlspecialchars($clientcookies, ENT_COMPAT, $inputcharset) . "\" />" .
                                 "<input type=\"hidden\" name=\"protocol\" value=\"$protocol\" />" .
-                                "<input type=\"hidden\" name=\"timeout\" value=\"" . htmlspecialchars($timeout) . "\" />" .
-                                "<input type=\"hidden\" name=\"method\" value=\"" . htmlspecialchars($method) . "\" />" .
-                                "<input type=\"hidden\" name=\"methodpayload\" value=\"" . htmlspecialchars($payload) . "\" />" .
-                                "<input type=\"hidden\" name=\"altmethodpayload\" value=\"" . htmlspecialchars($alt_payload) . "\" />" .
+                                "<input type=\"hidden\" name=\"timeout\" value=\"" . htmlspecialchars($timeout, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"method\" value=\"" . htmlspecialchars($method, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"methodpayload\" value=\"" . htmlspecialchars($payload, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"altmethodpayload\" value=\"" . htmlspecialchars($alt_payload, ENT_COMPAT, $inputcharset) . "\" />" .
                                 "<input type=\"hidden\" name=\"wstype\" value=\"$wstype\" />" .
                                 "<input type=\"hidden\" name=\"action\" value=\"execute\" />";
                             if ($wstype != 1) {
@@ -417,29 +438,29 @@ if ($action) {
                             echo "</form></td>\n";
 
                             echo "<td$class><form action=\"controller.php\" target=\"frmcontroller\" method=\"get\">" .
-                                "<input type=\"hidden\" name=\"host\" value=\"" . htmlspecialchars($host) . "\" />" .
-                                "<input type=\"hidden\" name=\"port\" value=\"" . htmlspecialchars($port) . "\" />" .
-                                "<input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars($path) . "\" />" .
-                                "<input type=\"hidden\" name=\"id\" value=\"" . htmlspecialchars($id) . "\" />" .
+                                "<input type=\"hidden\" name=\"host\" value=\"" . htmlspecialchars($host, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"port\" value=\"" . htmlspecialchars($port, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars($path, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"id\" value=\"" . htmlspecialchars($id, ENT_COMPAT, $inputcharset) . "\" />" .
                                 "<input type=\"hidden\" name=\"debug\" value=\"$debug\" />" .
-                                "<input type=\"hidden\" name=\"username\" value=\"" . htmlspecialchars($username) . "\" />" .
-                                "<input type=\"hidden\" name=\"password\" value=\"" . htmlspecialchars($password) . "\" />" .
+                                "<input type=\"hidden\" name=\"username\" value=\"" . htmlspecialchars($username, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"password\" value=\"" . htmlspecialchars($password, ENT_COMPAT, $inputcharset) . "\" />" .
                                 "<input type=\"hidden\" name=\"authtype\" value=\"$authtype\" />" .
                                 "<input type=\"hidden\" name=\"verifyhost\" value=\"$verifyhost\" />" .
                                 "<input type=\"hidden\" name=\"verifypeer\" value=\"$verifypeer\" />" .
-                                "<input type=\"hidden\" name=\"cainfo\" value=\"" . htmlspecialchars($cainfo) . "\" />" .
-                                "<input type=\"hidden\" name=\"proxy\" value=\"" . htmlspecialchars($proxy) . "\" />" .
-                                "<input type=\"hidden\" name=\"proxyuser\" value=\"" . htmlspecialchars($proxyuser) . "\" />" .
-                                "<input type=\"hidden\" name=\"proxypwd\" value=\"" . htmlspecialchars($proxypwd) . "\" />" .
+                                "<input type=\"hidden\" name=\"cainfo\" value=\"" . htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"proxy\" value=\"" . htmlspecialchars($proxy, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"proxyuser\" value=\"" . htmlspecialchars($proxyuser, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"proxypwd\" value=\"" . htmlspecialchars($proxypwd, ENT_COMPAT, $inputcharset) . "\" />" .
                                 "<input type=\"hidden\" name=\"responsecompression\" value=\"$responsecompression\" />" .
                                 "<input type=\"hidden\" name=\"requestcompression\" value=\"$requestcompression\" />" .
-                                "<input type=\"hidden\" name=\"clientcookies\" value=\"" . htmlspecialchars($clientcookies) . "\" />" .
+                                "<input type=\"hidden\" name=\"clientcookies\" value=\"" . htmlspecialchars($clientcookies, ENT_COMPAT, $inputcharset) . "\" />" .
                                 "<input type=\"hidden\" name=\"protocol\" value=\"$protocol\" />" .
-                                "<input type=\"hidden\" name=\"timeout\" value=\"" . htmlspecialchars($timeout) . "\" />" .
-                                "<input type=\"hidden\" name=\"method\" value=\"" . htmlspecialchars($method) . "\" />" .
+                                "<input type=\"hidden\" name=\"timeout\" value=\"" . htmlspecialchars($timeout, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"method\" value=\"" . htmlspecialchars($method, ENT_COMPAT, $inputcharset) . "\" />" .
                                 "<input type=\"hidden\" name=\"methodsig\" value=\"" . $i . "\" />" .
-                                "<input type=\"hidden\" name=\"methodpayload\" value=\"" . htmlspecialchars($payload) . "\" />" .
-                                "<input type=\"hidden\" name=\"altmethodpayload\" value=\"" . htmlspecialchars($alt_payload) . "\" />" .
+                                "<input type=\"hidden\" name=\"methodpayload\" value=\"" . htmlspecialchars($payload, ENT_COMPAT, $inputcharset) . "\" />" .
+                                "<input type=\"hidden\" name=\"altmethodpayload\" value=\"" . htmlspecialchars($alt_payload, ENT_COMPAT, $inputcharset) . "\" />" .
                                 "<input type=\"hidden\" name=\"wstype\" value=\"$wstype\" />" .
                                 "<input type=\"hidden\" name=\"run\" value=\"now\" />" .
                                 "<input type=\"hidden\" name=\"action\" value=\"wrap\" />" .
@@ -454,7 +475,7 @@ if ($action) {
                 case 'wrap':
                     $r1 = $resp[0]->value();
                     $r2 = $resp[1]->value();
-                    if ($r2->kindOf() != "array" || $r2->arraysize() <= $methodsig) {
+                    if ($r2->kindOf() != "array" || $r2->count() <= $methodsig) {
                         echo "Error: signature unknown\n";
                     } else {
                         $mdesc = $r1->scalarval();
@@ -465,18 +486,17 @@ if ($action) {
                         if ($proxy == '' && $username == '' && !$requestcompression && !$responsecompression &&
                             $clientcookies == ''
                         ) {
-                            $opts = 0; // simple client copy in stub code
+                            $opts = 1; // simple client copy in stub code
                         } else {
-                            $opts = 1; // complete client copy in stub code
+                            $opts = 0; // complete client copy in stub code
                         }
                         if ($wstype == 1) {
                             $prefix = 'jsonrpc';
                         } else {
                             $prefix = 'xmlrpc';
                         }
-                        //$code = wrap_xmlrpc_method($client, $method, $methodsig, 0, $proto, '', $opts);
                         $wrapper = new PhpXmlRpc\Wrapper();
-                        $code = $wrapper->build_remote_method_wrapper_code($client, $method, str_replace('.', '_', $prefix . '_' . $method), $msig, $mdesc, $timeout, $proto, $opts, $prefix);
+                        $code = $wrapper->buildWrapMethodSource($client, $method, array('timeout' => $timeout, 'protocol' => $proto, 'simple_client_copy' => $opts, 'prefix' => $prefix), str_replace('.', '_', $prefix . '_' . $method), $msig, $mdesc);
                         //if ($code)
                         //{
                         echo "<div id=\"phpcode\">\n";
@@ -528,6 +548,8 @@ if ($action) {
 
     <h3>Changelog</h3>
     <ul>
+        <li>2015-05-30: fix problems with generating method payloads for NIL and Undefined parameters</li>
+        <li>2015-04-19: fix problems with LATIN-1 characters in payload</li>
         <li>2007-02-20: add visual editor for method payload; allow strings, bools as jsonrpc msg id</li>
         <li>2006-06-26: support building php code stub for calling remote methods</li>
         <li>2006-05-25: better support for long running queries; check for no-curl installs</li>