X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=debugger%2Faction.php;h=0d0a649eda2849dfed7bb893da0eca3bd076d032;hb=d8e180b0ca87bf675d5fda2099d49c9d0043cd42;hp=b12da80465d507970e426620800a0a4dbb8d565c;hpb=b825566f55fd1aa4dab6b09145848e7d6e957fe5;p=plcapi.git diff --git a/debugger/action.php b/debugger/action.php index b12da80..0d0a649 100644 --- a/debugger/action.php +++ b/debugger/action.php @@ -1,13 +1,16 @@ @@ -91,31 +94,33 @@ include __DIR__ . '/common.php'; if ($action) { + include_once __DIR__ . "/../src/Autoloader.php"; + PhpXmlRpc\Autoloader::register(); + // make sure the script waits long enough for the call to complete... if ($timeout) { set_time_limit($timeout + 10); } - include 'xmlrpc.inc'; if ($wstype == 1) { @include 'jsonrpc.inc'; if (!class_exists('jsonrpc_client')) { die('Error: to debug the jsonrpc protocol the jsonrpc.inc file is needed'); } - $clientclass = 'jsonrpc_client'; - $msgclass = 'jsonrpcmsg'; - $protoname = 'JSONRPC'; + $clientClass = 'PhpJsRpc\Client'; + $requestClass = 'PhpJsRpc\Request'; + $protoName = 'JSONRPC'; } else { - $clientclass = 'xmlrpc_client'; - $msgclass = 'xmlrpcmsg'; - $protoname = 'XMLRPC'; + $clientClass = 'PhpXmlRpc\Client'; + $requestClass = 'PhpXmlRpc\Request'; + $protoName = 'XMLRPC'; } if ($port != "") { - $client = new $clientclass($path, $host, $port); + $client = new $clientClass($path, $host, $port); $server = "$host:$port$path"; } else { - $client = new $clientclass($path, $host); + $client = new $clientClass($path, $host); $server = "$host$path"; } if ($protocol == 2) { @@ -189,30 +194,24 @@ if ($action) { $msg = array(); switch ($action) { - - case 'wrap': - @include 'xmlrpc_wrappers.inc'; - if (!function_exists('build_remote_method_wrapper_code')) { - die('Error: to enable creation of method stubs the xmlrpc_wrappers.inc file is needed'); - } // fall thru intentionally case 'describe': case 'wrap': - $msg[0] = new $msgclass('system.methodHelp', array(), $id); - $msg[0]->addparam(new xmlrpcval($method)); - $msg[1] = new $msgclass('system.methodSignature', array(), $id + 1); - $msg[1]->addparam(new xmlrpcval($method)); + $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]->addparam(new PhpXmlRpc\Value($method)); $actionname = 'Description of method "' . $method . '"'; break; case 'list': - $msg[0] = new $msgclass('system.listMethods', array(), $id); + $msg[0] = new $requestClass('system.listMethods', array(), $id); $actionname = 'List of available methods'; break; case 'execute': if (!payload_is_safe($payload)) { die("Tsk tsk tsk, please stop it or I will have to call in the cops!"); } - $msg[0] = new $msgclass($method, array(), $id); + $msg[0] = new $requestClass($method, array(), $id); // hack! build xml payload by hand if ($wstype == 1) { $msg[0]->payload = "{\n" . @@ -230,7 +229,7 @@ if ($action) { } } } else { - $msg[0]->payload = $msg[0]->xml_header() . + $msg[0]->payload = $msg[0]->xml_header($inputcharset) . '' . $method . "\n" . $payload . "\n" . $msg[0]->xml_footer(); @@ -243,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 '

' . htmlspecialchars($actionname) . ' on server ' . htmlspecialchars($server) . " ...

\n"; + echo '

' . htmlspecialchars($actionname, ENT_COMPAT, $inputcharset) . ' on server ' . htmlspecialchars($server, ENT_COMPAT, $inputcharset) . " ...

\n"; flush(); $response = null; @@ -252,18 +251,16 @@ if ($action) { echo '

Debug info:

'; } /// @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); + @$response = $client->send($message, $timeout, $httpprotocol); $resp[] = $response; if (!$response || $response->faultCode()) { break; } } - $mtime = explode(' ', microtime()); - $time = (float)$mtime[0] + (float)$mtime[1] - $time; + $time = microtime(true) - $time; if ($debug) { echo "
\n"; } @@ -271,15 +268,15 @@ if ($action) { if ($response) { if ($response->faultCode()) { // call failed! echo out error msg! - //echo '

'.htmlspecialchars($actionname).' on server '.htmlspecialchars($server).'

'; - echo "

$protoname call FAILED!

\n"; - echo "

Fault code: [" . htmlspecialchars($response->faultCode()) . - "] Reason: '" . htmlspecialchars($response->faultString()) . "'

\n"; + //echo '

'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'

'; + echo "

$protoName call FAILED!

\n"; + echo "

Fault code: [" . htmlspecialchars($response->faultCode(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . + "] Reason: '" . htmlspecialchars($response->faultString(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "'

\n"; echo(strftime("%d/%b/%Y:%H:%M:%S\n")); } else { // call succeeded: parse results - //echo '

'.htmlspecialchars($actionname).' on server '.htmlspecialchars($server).'

'; - printf("

%s call(s) OK (%.2f secs.)

\n", $protoname, $time); + //echo '

'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'

'; + printf("

%s call(s) OK (%.2f secs.)

\n", $protoName, $time); echo(strftime("%d/%b/%Y:%H:%M:%S\n")); switch ($action) { @@ -287,44 +284,43 @@ if ($action) { $v = $response->value(); if ($v->kindOf() == "array") { - $max = $v->arraysize(); + $max = $v->count(); echo "\n"; - echo "\n\n\n\n"; - for ($i = 0; $i < $max; $i++) { - $rec = $v->arraymem($i); + echo "\n\n\n\n"; + foreach($v as $i => $rec) { if ($i % 2) { $class = ' class="oddrow"'; } else { $class = ' class="evenrow"'; } - echo("" . htmlspecialchars($rec->scalarval()) . "
" . - "" . - "" . - "" . - "" . + echo("
" . htmlspecialchars($rec->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "" . + "" . + "" . + "" . + "" . "" . - "" . - "" . + "" . + "" . "" . "" . "" . - "" . - "" . - "" . - "" . + "" . + "" . + "" . + "" . "" . "" . - "" . + "" . "" . - "" . - "scalarval() . "\" />" . + "" . + "scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "\" />" . "" . "" . "" . ""); //echo("\n"); - // generate lo scheletro per il method payload per eventuali test + // generate the skeleton for method payload per possible tests //$methodpayload="\n".$rec->scalarval()."\n\n\n\n"; /*echo ("
MethodDescription
Method ($max)Description
". @@ -347,37 +343,51 @@ if ($action) { $r2 = $resp[1]->value(); echo "\n"; - echo "\n\n\n\n"; - $desc = htmlspecialchars($r1->scalarval()); + echo "\n\n\n\n"; + $desc = htmlspecialchars($r1->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding); if ($desc == "") { $desc = "-"; } echo "\n"; - $payload = ""; - $alt_payload = ""; + if ($r2->kindOf() != "array") { echo "\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 "Signature " . ($i + 1) . ""; - $x = $r2->arraymem($i); if ($x->kindOf() == "array") { - $ret = $x->arraymem(0); - echo "OUT: " . htmlspecialchars($ret->scalarval()) . "
IN: ("; - if ($x->arraysize() > 1) { - for ($k = 1; $k < $x->arraysize(); $k++) { - $y = $x->arraymem($k); - echo $y->scalarval(); + $ret = $x[0]; + echo "OUT: " . htmlspecialchars($ret->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "
IN: ("; + 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 . '<' . htmlspecialchars($y->scalarval()) . '>scalarval()) . ">\n"; + $type = $y->scalarval(); + $payload .= ''; + switch($type) { + case 'undefined': + break; + case 'null'; + $type = 'nil'; + // fall thru intentionally + default: + $payload .= '<' . + htmlspecialchars($type, ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . + '>'; + } + $payload .= "\n"; } $alt_payload .= $y->scalarval(); - if ($k < $x->arraysize() - 1) { + if ($k < $x->count() - 1) { $alt_payload .= ';'; echo ", "; } @@ -388,31 +398,31 @@ if ($action) { echo 'Unknown'; } echo ''; - //bottone per testare questo metodo + // button to test this method //$payload="\n$method\n\n$payload\n"; echo "" . - "" . - "" . - "" . - "" . + "" . + "" . + "" . + "" . "" . - "" . - "" . + "" . + "" . "" . "" . "" . - "" . - "" . - "" . - "" . + "" . + "" . + "" . + "" . "" . "" . - "" . + "" . "" . - "" . - "" . - "" . - "" . + "" . + "" . + "" . + "" . "" . ""; if ($wstype != 1) { @@ -421,29 +431,29 @@ if ($action) { echo "\n"; echo "
" . - "" . - "" . - "" . - "" . + "" . + "" . + "" . + "" . "" . - "" . - "" . + "" . + "" . "" . "" . "" . - "" . - "" . - "" . - "" . + "" . + "" . + "" . + "" . "" . "" . - "" . + "" . "" . - "" . - "" . + "" . + "" . "" . - "" . - "" . + "" . + "" . "" . "" . "" . @@ -458,27 +468,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(); - $msig = php_xmlrpc_decode($r2); + $encoder = new PhpXmlRpc\Encoder(); + $msig = $encoder->decode($r2); $msig = $msig[$methodsig]; $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); - $code = build_remote_method_wrapper_code($client, $method, str_replace('.', '_', $prefix . '_' . $method), $msig, $mdesc, $timeout, $proto, $opts, $prefix); + $wrapper = new PhpXmlRpc\Wrapper(); + $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 "
\n"; @@ -504,7 +515,7 @@ if ($action) { // no action taken yet: give some instructions on debugger usage ?> -

Instructions on usage of the debugger:

+

Instructions on usage of the debugger

  1. Run a 'list available methods' action against desired server
  2. If list of methods appears, click on 'describe method' for desired method
  3. @@ -518,18 +529,20 @@ if ($action) { } ?> -

    Example:

    +

    Example

    Server Address: phpxmlrpc.sourceforge.net
    Path: /server.php

    -

    Notice:

    +

    Notice

    all usernames and passwords entered on the above form will be written to the web server logs of this server. Use with care.

    Changelog

      +
    • 2015-05-30: fix problems with generating method payloads for NIL and Undefined parameters
    • +
    • 2015-04-19: fix problems with LATIN-1 characters in payload
    • 2007-02-20: add visual editor for method payload; allow strings, bools as jsonrpc msg id
    • 2006-06-26: support building php code stub for calling remote methods
    • 2006-05-25: better support for long running queries; check for no-curl installs
Method" . htmlspecialchars($method) . "  
Method" . htmlspecialchars($method, ENT_COMPAT, $inputcharset) . "  
Description$desc
SignatureUnknown