nitpicks
[plcapi.git] / debugger / action.php
index 05cc99a..c7f88de 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * @author Gaetano Giunta
- * @copyright (C) 2005-2015 G. Giunta
+ * @copyright (C) 2005-2021 G. Giunta
  * @license code licensed under the BSD License: see file license.txt
  *
  * @todo switch params for http compression from 0,1,2 to values to be used directly
@@ -14,7 +14,7 @@ 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">
-<html xmlns="http://www.w3.org/1999/xhtml">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
 <head>
     <title>XMLRPC Debugger</title>
     <meta name="robots" content="index,nofollow"/>
@@ -92,10 +92,8 @@ header('Content-Type: text/html; charset=utf-8');
 <?php
 
 include __DIR__ . '/common.php';
-if ($action) {
 
-    include_once __DIR__ . "/../src/Autoloader.php";
-    PhpXmlRpc\Autoloader::register();
+if ($action) {
 
     // make sure the script waits long enough for the call to complete...
     if ($timeout) {
@@ -103,16 +101,16 @@ if ($action) {
     }
 
     if ($wstype == 1) {
-        @include 'jsonrpc.inc';
-        if (!class_exists('jsonrpc_client')) {
-            die('Error: to debug the jsonrpc protocol the jsonrpc.inc file is needed');
+        //@include 'jsonrpc.inc';
+        if (!class_exists('\PhpXmlRpc\JsonRpc\Client')) {
+            die('Error: to debug the jsonrpc protocol the phpxmlrpc/jsonrpc package is needed');
         }
-        $clientClass = 'PhpJsRpc\Client';
-        $requestClass = 'PhpJsRpc\Request';
+        $clientClass = '\PhpXmlRpc\JsonRpc\Client';
+        $requestClass = '\PhpXmlRpc\JsonRpc\Request';
         $protoName = 'JSONRPC';
     } else {
-        $clientClass = 'PhpXmlRpc\Client';
-        $requestClass = 'PhpXmlRpc\Request';
+        $clientClass = '\PhpXmlRpc\Client';
+        $requestClass = '\PhpXmlRpc\Request';
         $protoName = 'XMLRPC';
     }
 
@@ -199,7 +197,7 @@ if ($action) {
         case 'wrap':
             $msg[0] = new $requestClass('system.methodHelp', array(), $id);
             $msg[0]->addparam(new PhpXmlRpc\Value($method));
-            $msg[1] = new $requestClass('system.methodSignature', array(), $id + 1);
+            $msg[1] = new $requestClass('system.methodSignature', array(), (int)$id + 1);
             $msg[1]->addparam(new PhpXmlRpc\Value($method));
             $actionname = 'Description of method "' . $method . '"';
             break;
@@ -284,11 +282,10 @@ 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 ($max)</th><th>Description</th></tr>\n</thead>\n<tbody>\n";
-                        for ($i = 0; $i < $max; $i++) {
-                            $rec = $v->arraymem($i);
+                        foreach($v as $i => $rec) {
                             if ($i % 2) {
                                 $class = ' class="oddrow"';
                             } else {
@@ -350,34 +347,45 @@ if ($action) {
                         $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++) {
+                        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);
                             if ($x->kindOf() == "array") {
-                                $ret = $x->arraymem(0);
+                                $ret = $x[0];
                                 echo "<code>OUT:&nbsp;" . htmlspecialchars($ret->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "<br />IN: (";
-                                if ($x->arraysize() > 1) {
-                                    for ($k = 1; $k < $x->arraysize(); $k++) {
-                                        $y = $x->arraymem($k);
+                                if ($x->count() > 1) {
+                                    foreach($x as $k => $y) {
+                                        if ($k == 0) continue;
                                         echo htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding);
                                         if ($wstype != 1) {
-                                            $payload = $payload . '<param><value><' .
-                                                htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
-                                                '></' . htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
-                                                "></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 ", ";
                                         }
@@ -458,29 +466,28 @@ 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();
                         $encoder = new PhpXmlRpc\Encoder();
                         $msig = $encoder->decode($r2);
                         $msig = $msig[$methodsig];
-                        $proto = $protocol == 2 ? 'https' : $protocol == 1 ? 'http11' : '';
+                        $proto = $protocol == 2 ? 'https' : ( $protocol == 1 ? 'http11' : '' );
                         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";
@@ -532,6 +539,8 @@ if ($action) {
 
     <h3>Changelog</h3>
     <ul>
+        <li>2020-12-11: fix problems with running the debugger on php 8</li>
+        <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>