Skip to content

Commit f50d88c

Browse files
committed
add support for jsonrpc 2.0 to the debugger
1 parent ad2d4bb commit f50d88c

5 files changed

Lines changed: 85 additions & 32 deletions

File tree

NEWS.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
## XML-RPC for PHP version 4.XXX - (unreleased)
22

3-
- improved: allow to force usage of HTTP 1.1. when using curl for calls, via usage of 'http11_only'
3+
* improved: allow to force usage of HTTP 1.1. when using curl for calls, via usage of 'http11_only'
44

5-
- improved: added new methods: `Server::generatePayload($resp, $respCharset)`,
5+
* improved: added new methods: `Server::generatePayload($resp, $respCharset)`,
66
`Server::printPayload($payload, $resp->getContentType(), $respEncoding)` and `HTTP::setAcceptedStatusCodes($statusCodes)`
77
to help subclasses such as the Json-Rpc server and request
88

9-
- fixed: the `vm.sh` script would not expose the http ports of the test contaienr to the host
9+
* fixed: the `vm.sh` script would not expose the http ports of the test container to the host
10+
11+
* changed: the debugger does now require phpjsonrpc 1.0.0-beta3 or later in order to support json-rpc calls
1012

1113

1214
## XML-RPC for PHP version 4.11.3 - 2025/10/3
1315

14-
- improved: fixed deprecation warnings on PHP 8.5
16+
* improved: fixed deprecation warnings on PHP 8.5
1517

16-
- improved: added CI testing on PHP 8.5
18+
* improved: added CI testing on PHP 8.5
1719

18-
- improved: teach the vm.sh script how to properly configure test envs using PHP 8.5
20+
* improved: teach the vm.sh script how to properly configure test envs using PHP 8.5
1921

20-
- improved: do not hardcode `/tmp` as temporary dir in demo files
22+
* improved: do not hardcode `/tmp` as temporary dir in demo files
2123

2224

2325
## XML-RPC for PHP version 4.11.2 - 2025/6/20

debugger/action.php

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<html lang="en">
1616
<head>
1717
<link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico">
18-
<title><?php if (defined('DEFAULT_WSTYPE') && DEFAULT_WSTYPE == 1) echo 'JSON-RPC'; else echo 'XML-RPC'; ?> Debugger</title>
18+
<title><?php if (defined('DEFAULT_WSTYPE') && (DEFAULT_WSTYPE == 1 || DEFAULT_WSTYPE == 2)) echo 'JSON-RPC'; else echo 'XML-RPC'; ?> Debugger</title>
1919
<meta name="robots" content="index,nofollow"/>
2020
<style type="text/css">
2121
<!--
@@ -78,6 +78,10 @@
7878
<body>
7979
<?php
8080

81+
global $inputcharset, $debug, $protocol, $run, $hasjsonrpcclient, $wstype, $id, $host, $port, $path, $action, $method, $methodsig,
82+
$payload, $alt_payload, $username, $password, $authtype, $verifyhost, $verifypeer, $cainfo, $proxy, $proxyuser,
83+
$proxypwd, $timeout, $requestcompression, $responsecompression, $clientcookies;
84+
8185
include __DIR__ . '/common.php';
8286

8387
if ($action) {
@@ -100,7 +104,7 @@
100104
set_time_limit($timeout + 10);
101105
}
102106

103-
if ($wstype == 1) {
107+
if ($wstype == 1 || $wstype == 2) {
104108
$clientClass = '\PhpXmlRpc\JsonRpc\Client';
105109
$requestClass = '\PhpXmlRpc\JsonRpc\Request';
106110
$protoName = 'JSON-RPC';
@@ -197,14 +201,26 @@
197201
// fall thru intentionally
198202
case 'describe':
199203
case 'wrap':
200-
$msg[0] = new $requestClass('system.methodHelp', array(), $id);
204+
$msg[0] = new $requestClass('system.methodHelp', array(), (int)$id);
201205
$msg[0]->addparam(new PhpXmlRpc\Value($method));
202206
$msg[1] = new $requestClass('system.methodSignature', array(), (int)$id + 1);
203207
$msg[1]->addparam(new PhpXmlRpc\Value($method));
208+
if ($wstype == 2) {
209+
$msg[0]->setJsonRpcVersion('2.0');
210+
$msg[1]->setJsonRpcVersion('2.0');
211+
} elseif ($wstype == 1) {
212+
$msg[0]->setJsonRpcVersion('1.0');
213+
$msg[1]->setJsonRpcVersion('1.0');
214+
}
204215
$actionname = 'Description of method "' . $method . '"';
205216
break;
206217
case 'list':
207-
$msg[0] = new $requestClass('system.listMethods', array(), $id);
218+
$msg[0] = new $requestClass('system.listMethods', array(), (int)$id);
219+
if ($wstype == 2) {
220+
$msg[0]->setJsonRpcVersion('2.0');
221+
} elseif ($wstype == 1) {
222+
$msg[0]->setJsonRpcVersion('1.0');
223+
}
208224
$actionname = 'List of available methods';
209225
break;
210226
case 'execute':
@@ -213,7 +229,24 @@
213229
}
214230
$msg[0] = new $requestClass($method, array(), $id);
215231
// hack! build payload by hand
216-
if ($wstype == 1) {
232+
if ($wstype == 2) {
233+
$payload = "{\n" .
234+
'"jsonrpc": "2.0"' . "\n" .
235+
'"method": "' . $method . "\",\n\"params\": [" .
236+
$payload .
237+
"\n],\n";
238+
// fix: if user gave an empty string, use NULL, or we'll break json syntax
239+
if ($id != "") {
240+
if (is_numeric($id) || $id == 'false' || $id == 'true') {
241+
$payload .= "\"id\": $id\n";
242+
} else {
243+
$payload .= "\"id\": \"$id\"\n";
244+
}
245+
}
246+
$payload .= '}';
247+
$msg[0]->setPayload($payload);
248+
$msg[0]->setJsonRpcVersion('2.0');
249+
} elseif ($wstype == 1) {
217250
$payload = "{\n" .
218251
'"method": "' . $method . "\",\n\"params\": [" .
219252
$payload .
@@ -229,6 +262,7 @@
229262
}
230263
}
231264
$msg[0]->setPayload($payload);
265+
$msg[0]->setJsonRpcVersion('1.0');
232266
} else {
233267
$msg[0]->setPayload(
234268
$msg[0]->xml_header($inputcharset) .
@@ -372,7 +406,7 @@
372406
foreach($x as $k => $y) {
373407
if ($k == 0) continue;
374408
echo htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding);
375-
if ($wstype == 1) {
409+
if ($wstype == 1 || $wstype == 2) {
376410
switch($y->scalarval()) {
377411
case 'string':
378412
case 'dateTime.iso8601':
@@ -423,7 +457,7 @@
423457
$alt_payload .= $y->scalarval();
424458
if ($k < $x->count() - 1) {
425459
$alt_payload .= ';';
426-
if ($wstype == 1) {
460+
if ($wstype == 1 || $wstype == 2) {
427461
$payload .= ', ';
428462
}
429463
echo ", ";
@@ -519,12 +553,12 @@
519553
} else {
520554
$opts = 0; // complete client copy in stub code
521555
}
522-
if ($wstype == 1) {
556+
if ($wstype == 1 || $wstype == 2) {
523557
$prefix = 'jsonrpc';
524558
} else {
525559
$prefix = 'xmlrpc';
526560
}
527-
if ($wstype == 1) {
561+
if ($wstype == 1 || $wstype == 2) {
528562
$wrapper = new PhpXmlRpc\JsonRpc\Wrapper();
529563
} else {
530564
$wrapper = new PhpXmlRpc\Wrapper();
@@ -586,6 +620,7 @@
586620

587621
<h3>Changelog</h3>
588622
<ul>
623+
<li>2025-10-08: added support for json-rpc 2.0. The debugger now require phpjsonrpc 1.0.0-beta3 or later for json-rpc support</li>
589624
<li>2023-02-11: display in the top row the version of the libraries in use; made the generated code throw instead
590625
of returning a Response object on error; fixes for the json-rpc debugger</li>
591626
<li>2022-12-18: fix XSS vulnerability in the debugger; load jsxmlrpc from CDN; minor improvements</li>

debugger/common.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ function stripslashes_deep($value)
8585
$wstype = defined('DEFAULT_WSTYPE') ? DEFAULT_WSTYPE : 0;
8686
$id = '';
8787
if (isset($_GET['action'])) {
88-
if (isset($_GET['wstype']) && ($_GET['wstype'] == '1' || $_GET['wstype'] == '0')) {
88+
if (isset($_GET['wstype']) && ($_GET['wstype'] == '2' || $_GET['wstype'] == '1' || $_GET['wstype'] == '0')) {
8989
$wstype = (int)$_GET['wstype'];
90-
if ($wstype === 1 && !$hasjsonrpcclient) {
90+
if (($wstype === 1 || $wstype === 2) && !$hasjsonrpcclient) {
9191
$wstype = 0;
9292
}
93-
if ($wstype === 1 && isset($_GET['id'])) {
93+
if (($wstype === 1 || $wstype === 2) && isset($_GET['id'])) {
9494
$id = $_GET['id'];
9595
}
9696
}

debugger/controller.php

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
// Make sure we set the correct charset type for output, so that we can display all characters
1818
header('Content-Type: text/html; charset=utf-8');
1919

20+
global $inputcharset, $debug, $protocol, $run, $hasjsonrpcclient, $wstype, $id, $host, $port, $path, $action, $method, $methodsig,
21+
$payload, $alt_payload, $username, $password, $authtype, $verifyhost, $verifypeer, $cainfo, $proxy, $proxyuser,
22+
$proxypwd, $timeout, $requestcompression, $responsecompression, $clientcookies;
23+
2024
include __DIR__ . '/common.php';
25+
2126
if ($action == '') {
2227
$action = 'list';
2328
}
@@ -66,7 +71,7 @@
6671
<html lang="en">
6772
<head>
6873
<link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico">
69-
<title><?php if (defined('DEFAULT_WSTYPE') && DEFAULT_WSTYPE == 1) echo 'JSON-RPC'; else echo 'XML-RPC'; ?> Debugger</title>
74+
<title><?php if (defined('DEFAULT_WSTYPE') && (DEFAULT_WSTYPE == 1 || DEFAULT_WSTYPE == 2)) echo 'JSON-RPC'; else echo 'XML-RPC'; ?> Debugger</title>
7075
<meta name="robots" content="index,nofollow"/>
7176
<script type="text/javascript" language="Javascript">
7277
if (window.name != 'frmcontroller')
@@ -209,18 +214,26 @@ function swicthcainfo() {
209214
}
210215

211216
function switchtransport(is_json) {
212-
if (is_json == 0) {
213-
document.getElementById("idcell").style.visibility = 'hidden';
214-
document.frmjsonrpc.yes.checked = false;
215-
document.frmxmlrpc.yes.checked = true;
216-
document.frmaction.wstype.value = "0";
217-
}
218-
else {
217+
if (is_json == 2) {
219218
document.getElementById("idcell").style.visibility = 'visible';
220-
document.frmjsonrpc.yes.checked = true;
219+
document.frmjsonrpc2.yes.checked = true;
220+
document.frmjsonrpc1.yes.checked = false;
221+
document.frmxmlrpc.yes.checked = false;
222+
document.frmaction.wstype.value = "2";
223+
} else if (is_json == 1) {
224+
document.getElementById("idcell").style.visibility = 'visible';
225+
document.frmjsonrpc2.yes.checked = false;
226+
document.frmjsonrpc1.yes.checked = true;
221227
document.frmxmlrpc.yes.checked = false;
222228
document.frmaction.wstype.value = "1";
223229
}
230+
else {
231+
document.getElementById("idcell").style.visibility = 'hidden';
232+
document.frmjsonrpc2.yes.checked = false;
233+
document.frmjsonrpc1.yes.checked = false;
234+
document.frmxmlrpc.yes.checked = true;
235+
document.frmaction.wstype.value = "0";
236+
}
224237
}
225238

226239
function displaydialogeditorbtn(show) {
@@ -234,7 +247,7 @@ function displaydialogeditorbtn(show) {
234247

235248
function activateeditor() {
236249
var url = '<?php echo $editorurlpath; ?>visualeditor.html?params=<?php echo str_replace(array("\\", "'"), array( "\\\\", "\\'"), $alt_payload); ?>';
237-
if (document.frmaction.wstype.value == "1")
250+
if (document.frmaction.wstype.value == "1" || document.frmaction.wstype.value == "2")
238251
url += '&type=jsonrpc';
239252
var wnd = window.open(url, '_blank', 'width=750, height=400, location=0, resizable=1, menubar=0, scrollbars=1');
240253
}
@@ -274,8 +287,11 @@ function switchFormMethod() {
274287
echo '<form name="frmxmlrpc" style="display: inline;" action="."><input name="yes" type="radio" onclick="switchtransport(0);"';
275288
// q: does this if make sense at all?
276289
if (!class_exists('\PhpXmlRpc\Client')) echo ' disabled="disabled"';
277-
echo ' /></form> / <form name="frmjsonrpc" style="display: inline;" action="."><input name="yes" type="radio" onclick="switchtransport(1);"/></form>
278-
JSON-RPC';
290+
echo ' /></form>';
291+
echo ' / <form name="frmjsonrpc2" style="display: inline;" action="."><input name="yes" type="radio" onclick="switchtransport(2);"/></form>
292+
JSON-RPC 2.0 ';
293+
echo ' / <form name="frmjsonrpc1" style="display: inline;" action="."><input name="yes" type="radio" onclick="switchtransport(1);"/></form>
294+
JSON-RPC 1.0 ';
279295
} ?>
280296
Debugger</h1><h3>(based on <a href="https://gggeek.github.io/phpxmlrpc/">PHPXMLRPC</a>, ver. <?php echo htmlspecialchars(\PhpXmlRpc\PhpXmlRpc::$xmlrpcVersion)?>
281297
<?php if (class_exists('\PhpXmlRpc\JsonRpc\PhpJsonRpc')) echo ' and <a href="https://gggeek.github.io/phpxmlrpc-jsonrpc/">PHPJOSNRPC</a>, ver. ' . htmlspecialchars(\PhpXmlRpc\JsonRpc\PhpJsonRpc::$jsonrpcVersion); ?>)</h3>

debugger/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<html lang="en">
1414
<head>
1515
<link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico">
16-
<title><?php if (defined('DEFAULT_WSTYPE') && DEFAULT_WSTYPE == 1) echo 'JSON-RPC'; else echo 'XML-RPC'; ?> Debugger</title>
16+
<title><?php if (defined('DEFAULT_WSTYPE') && (DEFAULT_WSTYPE == 1 || DEFAULT_WSTYPE == 2)) echo 'JSON-RPC'; else echo 'XML-RPC'; ?> Debugger</title>
1717
</head>
1818
<frameset rows="360,*">
1919
<frame name="frmcontroller" src="controller.php<?php echo htmlspecialchars($query); ?>" marginwidth="0"

0 commit comments

Comments
 (0)